manto07m 3 жил өмнө
parent
commit
c5064952ed

+ 16 - 10
script/php/video/getDir.php

@@ -1,25 +1,32 @@
 <?php
-if(isset($_POST["dir"])){
+if (isset($_POST["dir"])) {
     include("../connectSQL_Component.php");
 
     $tables = [];
     $file_tables = [];
     $dir_tables = [];
     $dir = $_POST["dir"];
-
-    $sql = "SELECT [title], [file_path] FROM [BIMComponents].[dbo].[Video_Table] WHERE dir_name = '".$dir."'";
+    $array = [];
+    $sql = "SELECT [title], [file_path] FROM [BIMComponents].[dbo].[Video_Table] WHERE dir_name = '" . $dir . "'";
     $fetchResult = sqlsrv_query($conn, $sql);
-    while ($row = sqlsrv_fetch_array($fetchResult)) {
-        array_push($file_tables,$row);
+    while ($row = sqlsrv_fetch_array($fetchResult, SQLSRV_FETCH_ASSOC)) {
+        array_push($file_tables, $row);
     }
 
-    $sql = "SELECT [dir_name] FROM [BIMComponents].[dbo].[Video_Node] WHERE parent = '".$dir."'";
+    $sql = "SELECT [dir_name] FROM [BIMComponents].[dbo].[Video_Node] WHERE [parent] = '" . $dir . "'";
+    $fetchResult = sqlsrv_query($conn, $sql);
+    while ($row = sqlsrv_fetch_array($fetchResult, SQLSRV_FETCH_ASSOC)) {
+        array_push($dir_tables, $row);
+    }
+    $sql = "SELECT [parent] FROM [BIMComponents].[dbo].[Video_Node] WHERE [dir_name] = '" . $dir . "'";
     $fetchResult = sqlsrv_query($conn, $sql);
-    while ($row = sqlsrv_fetch_array($fetchResult)) {
-        array_push($dir_tables,$row);
+    while ($row = sqlsrv_fetch_array($fetchResult, SQLSRV_FETCH_ASSOC)) {
+        $array["parent"] = $row["parent"];
     }
+    $array["dir_names"] = $dir_tables;
+    $array["file_tables"] = $file_tables;
 
-    echo json_encode($dir_tables);
+    echo json_encode($array);
 
     sqlsrv_close($conn);
 }
@@ -49,4 +56,3 @@ if(isset($_POST["dir"])){
             }
     }
 */
-    

+ 29 - 8
video-list.php

@@ -199,7 +199,7 @@ if (!isset($_SESSION['loggedin'])) {
 				<div class="row">
 					<div class="col-md-6">
 						<section class="panel">
-							<button type="button" onclick="goBack()">回上層</button>
+							<button type="button" onclick="goBack(parent)">回上層</button>
 							<div class="panel-body" id="video-list">
 
 							</div>
@@ -234,6 +234,7 @@ if (!isset($_SESSION['loggedin'])) {
 
 		var dirList = [];
 		var count = 0;
+		var parent = ".";
 
 		function initList(dir) {
 
@@ -246,7 +247,12 @@ if (!isset($_SESSION['loggedin'])) {
 					dir: dir,
 				},
 				dataType: "json"
-			}).done(function(data) {
+			}).done(function(result) {
+				console.log(result);
+				data = result["dir_names"];
+				data2 = result["file_tables"];
+				if (result["parent"] != undefined)
+					parent = result["parent"];
 
 				for (j = 0; j < data.length; j++) {
 
@@ -260,6 +266,25 @@ if (!isset($_SESSION['loggedin'])) {
 
 					var i = document.createElement("i");
 					i.setAttribute("class", "fa fa-folder");
+
+					p.appendChild(i);
+
+					p.appendChild(a);
+
+				}
+				for (j = 0; j < data2.length; j++) {
+
+					var p = document.createElement("p");
+					document.getElementById("video-list").appendChild(p);
+
+					var a = document.createElement("a");
+					a.setAttribute("href", "#");
+					//a.setAttribute("onclick", "initList('" + data2[j]["dir_name"] + "');");
+					a.innerText = data2[j]["title"];
+
+					var i = document.createElement("i");
+					i.setAttribute("class", "fa fa-video-camera");
+
 					p.appendChild(i);
 
 					p.appendChild(a);
@@ -282,15 +307,12 @@ if (!isset($_SESSION['loggedin'])) {
 		function removeChild() {
 			var parent = document.getElementById("video-list");
 			while (parent.firstChild) {
-				if (parent.firstChild.innerText != undefined) {
-					//dirList[count++] = [parent.firstChild.innerText];
-				}
 				parent.removeChild(parent.firstChild);
 			}
 		}
 
-		function goBack() {
-			console.log(dirList, count);
+		function goBack(parent) {
+			initList(parent);
 
 		}
 	</script>
@@ -335,7 +357,6 @@ if (!isset($_SESSION['loggedin'])) {
 	<!-- Main-->
 	<script src="script/js/main.js"></script>
 
-	<script src='script/js/warning.js'></script>
 
 	</section>
 </body>