config_debug.php 9.9 KB
<?php 
session_start();
if($_SESSION['account'] != "" && $_SESSION['password'] != ""){
?>
<head>
<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">
	<link rel="stylesheet" type="text/css" href="css/menu.css">
	<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="css/dataTables.bootstrap.min.css">
	<style type="text/css" class="init">

	</style>
	<script src="js/jquery.min.js"></script>
	<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
	<script type="text/javascript" language="javascript" src="js/jquery.lightbox_me.js"></script>
	<script type="text/javascript" language="javascript" src="js/dataTables.bootstrap.min.js"></script>
	<script type="text/javascript" language="javascript" class="init">


		$(document).ready(function() {
			$('#example').DataTable({
				"order": false,
				"displayLength": 1000
			});
			 var table = $('#example').DataTable();
			$('.btn').click( function() {
				var data = table.$('input, select').serialize();
				$.ajax({
					url: 'update.php',
					data: data,
					type:"POST",
					dataType:'text',
					success: function(msg){
						alert('Success!!');
						location.href='main.php';
					},

					error:function(xhr, ajaxOptions, thrownError){ 
						alert(xhr.status); 
						alert(thrownError); 
					}
				});
				return false;
			} );
			
			$("#gotop").click(function(){
				jQuery("html,body").animate({
						scrollTop:0
					},0);
			});
			
			$(window).scroll(function() {
					if ( $(this).scrollTop() > 300){
						$('#gotop').fadeIn("fast");
					} else {
						$('#gotop').stop().fadeOut("fast");
					}
			});
			
			$(".add-click").click(function(e){
				var label = e.target.id;
				var str = label.replace('/[\s]+/g', '_')+'_input';
				$('#'+ str).lightbox_me({
					centered: true,
					onLoad: function() {
						$('#'+ label +'_input').find('input:first').focus()
						}
					});
				e.preventDefault();
			});
			
			
		} );

	</script>
	<style>
		#right{
			width:85%;
			float:right;
		}
		#cssmenu{
			float:left;
		}
		.btn {
		  border-radius: 5px;
		  padding: 0px 25px;
		  font-size: 22px;
		  text-decoration: none;
		  margin: 20px;
		  color: #fff;
		  position: relative;
		  display: inline-block;
		}

		.btn:active {
		  transform: translate(0px, 5px);
		  -webkit-transform: translate(0px, 5px);
		  box-shadow: 0px 1px 0px 0px;
		}

		.blue {
		  background-color: #55acee;
		  box-shadow: 0px 5px 0px 0px #3C93D5;
		}

		.blue:hover {
		  background-color: #6FC6FF;
		}
		#gotop {
			display: none;
			position: fixed;
			bottom: 20px;    
			padding: 10px 15px;    
			font-size: 20px;
			background: #777;
			color: white;
			cursor: pointer;
		}
		
		#config {
			position:fixed;
			top:80%; 
			z-index:1;
		}
		
		.hidden{
			display:none;
		}
	</style>
</head>
<?php
	include('file_name.php');
	$nn = 0;
	$handle = @fopen($open_file,"r");
	while(($data = fgetcsv($handle,1000,"\n")) != false){
		$i = 0;	
		foreach($data as $key => $value){
			$aa[$nn][$i] = $value;
			$i++;									
		}
		$nn++;
	}
fclose($handle);
	foreach($aa as $key => $value){		
		if($value[0] != ""){
			if(in_array($value[0],$file_name)){
				$topic = $value[0] ;
				$br = 1;
			}elseif($br){
				//echo $topic."|".$value[0]."<br>";
				$file[$topic][] =  $value[0];
			}else{
				$filename[] = $value[0];
			}
		}else{
			$br = 0;
		}
	}
?>

<!--左邊Menu列-->
<div id="config"><input type='submit' id='command' class="btn blue" value='Config' /></div>
<div id="gotop">回到最上方</div>
<div id='cssmenu' >

	<ul>
	   <li id='index' style="border-bottom: 3px solid #F00;"><a><span>INDEX</span></a></li>
	   <?php
		foreach($file as $key => $value){
			if(in_array($key,$hidden)){
			}else{
				echo "<li class='active has-sub'><a href='#".$key."'><span>".$key."</span></a>";
				echo "<ul>";
				foreach($value as $k => $v){
					$num = explode(' ',$v);	
					echo "<li><a href='#".$num[0]."'><span>".$num[0]."</span></a></li>";
				}
				echo "</ul></li>";
			}
		}
		echo "<li class=''><a href='#other'><span>OTHER</span></a>";
		/*foreach($file_name1 as $key => $value){
			echo "<li class=''><a href='#".$value."'><span>".$value."</span></a>";
		}*/
	   ?>
	</ul>
</div>

<!--右邊內容列-->
<div id='right'>
	<form action='update.php' method='post'>
	
		<table id='example' class='table table-striped table-bordered' cellspacing='0' width='100%'>
		<thead>
			<th style="width:70%">裝置名稱</th>
			<th>設定值</th>
		</thead>
		<tbody>
<?php
	//群組設定
	foreach($file as $key => $value){
		if(in_array($key,$hidden)){
			echo "<tr class='hidden' id='".$key."' style='background:rgba(181, 174, 174, 0.65);'><td>".$key."<input type='hidden' name='".$key."' value='".$key."'/></td><td>";
		}else{
			echo "<tr id='".$key."' style='background:rgba(181, 174, 174, 0.65);'><td>".$key."<input type='hidden' name='".$key."' value='".$key."'/></td><td>";
		}
		
		$str_replace = str_replace(' ','_',$key);
		echo (in_array($key,$name_rp)) ? "<img src='https://cdn1.iconfinder.com/data/icons/Koloria-Icon-Set/30/Add.png' id='".$str_replace."' class='add-click'":"";
		echo "</td></tr>";
		foreach($value as $k => $v){
		//判斷群組是否要隱藏
			if(in_array($key,$hidden)){
				$num = explode(' ',$v);
				echo "<tr class='hidden'>";
				$row_title = (substr($num[0],0,1) == "#") ? substr($num[0],1):$num[0];
				echo "<td id='".$row_title."'>".$row_title."</td>";
				
				//判斷是否可以重複新增
				if(in_array($row_title,$name_rp)){
					echo "<td><input type='text' name='".$key.",".$row_title."[]' value='".$num[1]."' />";
					$str_replace = str_replace(' ','_',$row_title);
					echo "<img src='https://cdn1.iconfinder.com/data/icons/Koloria-Icon-Set/30/Add.png' id='".$str_replace."' class='add-click'";
					$total_MATH += ($row_title == 'MATH') ? 1:0;
					$total_SERVER_IP += ($row_title == 'SERVER_IP') ? 1:0;
				}else{
					
					echo "<td><input type='text' name='".$key.",".$row_title."' value='".$num[1]."' />";
				}
				echo "</td>";
				echo "</tr>";
			
			}else{
			
				$num = explode(' ',$v);
				$row_title = (substr($num[0],0,1) == "#") ? substr($num[0],1):$num[0];
				//判斷群組內的標題是否要隱藏
				if(in_array($row_title,$hidden)){
				}else{
					echo "<tr>";
					echo "<td id='".$row_title."'>".$row_title."</td>";
					
					//判斷是否可以重複新增
					if(in_array($row_title,$name_rp)){
						echo "<td><input type='text' name='".$key.",".$row_title."[]' value='".$num[1]."' />";
						$str_replace = str_replace(' ','_',$row_title);
						echo "<img src='https://cdn1.iconfinder.com/data/icons/Koloria-Icon-Set/30/Add.png' id='".$str_replace."' class='add-click'";
						$total_MATH += ($row_title == 'MATH') ? 1:0;
						$total_SERVER_IP += ($row_title == 'SERVER_IP') ? 1:0;
					}else{
						
						echo "<td><input type='text' name='".$key.",".$row_title."' value='".$num[1]."' />";
					}
					echo "</td>";
					echo "</tr>";
				}
			}
		}
	}
	
	//非群組設定
	echo "<tr id='other' style='background:rgba(181, 174, 174, 0.65);'><td></td><td></td></tr>";
	$length = count($filename);
	for($i=0; $i < $length; $i++){
		//取下一筆資料,並去掉有#字號的標題
		$next = next($filename);
		$next_title = (substr($next,0,1) == "#") ? substr($next,1):$next;
		
		
		//判斷title有沒有在設定陣列內
		$row_title_other = (substr($filename[$i],0,1) == "#") ? substr($filename[$i],1):$filename[$i];
		if(in_array($row_title_other,$file_name1)){
			//先判斷下一筆是否為title
			if(in_array($next_title,$file_name1)){
				//此為下值為空白 再判斷是否要設為隱藏
				if(in_array($row_title_other,$hidden)){
					echo "<tr style='display:none'><td id='".$row_title_other."'>".$row_title_other."</td>";
				}else{
					echo "<tr><td id='".$row_title_other."'>".$row_title_other."</td>";
				}
				//判斷是否可以重複新增
				if(in_array($row_title_other,$name_rp)){
					echo "<td><input type='text' name='".$row_title_other."[]' value='' />";
					$str_replace = str_replace(' ','_',$row_title_other);
					echo "<img src='https://cdn1.iconfinder.com/data/icons/Koloria-Icon-Set/30/Add.png' id='".$str_replace."' class='add-click'";
				}else{
					echo "<td><input type='text' name='".$row_title_other."' value='' />";
				}
				echo "</td></tr>";
			}else{
			
				//判斷倒數第二筆資料是否有值
				if(in_array($row_title_other,$file_name1) && ($next == "")){
					echo "<tr><td>".$row_title_other."</td><td><input type='text' name='".$row_title_other."' /></td></tr>";
				
				}else{
					if(in_array($row_title_other,$hidden)){
						echo "<tr style='display: none;'><td></td>";
						$title = $row_title_other;
						$j = 1;
					}else{
						echo "<tr><td>".$row_title_other."</td>";
						$title = $row_title_other;
						$j = 1;
					}
					
				}
			}
		}elseif($j == 1){
			//判斷是否可以重複新增
			if(in_array($title,$name_rp)){
				if(in_array($title,$hidden)){
					echo "<td><input type='hidden' name='".$title."[]' value='".$filename[$i]."' />";
				}else{
					echo "<td><input type='text' name='".$title."[]' value='".$filename[$i]."' />";
					$str_replace = str_replace(' ','_',$title);
					echo "<img src='https://cdn1.iconfinder.com/data/icons/Koloria-Icon-Set/30/Add.png' id='".$str_replace."' class='add-click'";
				}
			}else{
				if(in_array($title,$hidden)){
					echo "<td><input type='hidden' name='".$title."' value='".$filename[$i]."' />";
				}else{
					echo "<td><input type='text' name='".$title."' value='".$filename[$i]."' />";
				}
			}
			echo "</td></tr>";
			$j++;
		}elseif($j > 1){
			echo "<tr><td>".$title."</td>";
			echo "<td><input type='text' name='".$title."[]' value='".$filename[$i]."' /></td></tr>";
			$j++;
		}else{
			if($filename[$i] != "BLOCK CONFIG BY ONE ITEM"){
				echo "<tr><td>".$filename[$i]."</td><td></td></tr>";
			}
		}
	}	
	
?>
		</tbody>
	</table>
	
	</form>
</div>
<?php 
	include('device_input.php'); 
}else{
	echo "<script>location.href = 'index.html'</script>";
}
?>