Blame view

view/config_debug.php 9.9 KB
cf76164e6   Ting Chan   20190709
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
  <?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,"
  ")) != 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>";
  }
  ?>