summaryrefslogtreecommitdiff
path: root/www/browse.php
blob: 4e126948ea662c7aa82b5eb7a7f07af559d7a53c (plain)
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
<?php



function print_browser($content){
//	require_once("include.php");
		
	if($_SERVER['REQUEST_METHOD'] == 'POST'){
		//echo "created_folder : ". $_POST["foldername"] . " in ". $_GET["folder"];
		if($_POST["task"]=="new-folder"){
			if(isset($_POST["share"])){
				$share = "PUBLIC";
			} else {
				$share= "PRIVATE";
			}
			create_folder($_POST["path"], $_POST["foldername"], $share);
		}elseif($_POST["task"]=="upload"){
			upload($_POST["path"]);
		}
		browse(collect_content($GLOBALS["db"], $_SESSION["username"] , $_POST["path"]));
	}else{
		browse(collect_content($GLOBALS["db"], $_GET["name"] , $_GET["folder"]));
	}
}

function browse($content){
		include("static/header.html");
		if($_SESSION["login"] && $_SESSION["username"] == $_GET["name"]){
			print_menu();
		}
	
	

		if($content != EMPTY_FOLDER){
			$file_list = "<tr><td colspan='2'><a class='file' id='up' href='/".$_GET["name"]."/".$_GET["folder"]."../'>&nbsp;..</a></td></tr>";
			foreach($content as $file){
				$file_list .= get_item($file);
			} 
		}else{
			$file_list = "<tr><td><a class='file' id='up' href='/".$_GET["name"]."/".$_GET["folder"]."../'>&nbsp;..</a></td></tr>";
		}
		
	
		echo '<link rel="stylesheet" type="text/css" href="/static/browser.css">
				<script>
					function showNewFolder(){
							document.getElementById("new-folder-bg").style.visibility = "visible";
							
							return;
					}
					function hideNewFolder(){
						document.getElementById("new-folder-bg").style.visibility = "hidden";
						return;
					}
				
					function showUpload(){
							document.getElementById("upload-bg").style.visibility = "visible";
							return;
					}
					function hideUpload(){
						document.getElementById("upload-bg").style.visibility = "hidden";
						return;
					}
					
					
					function showMenu(e) {
						var posx = e.clientX +window.pageXOffset +"px";
						var posy = e.clientY + window.pageYOffset + "px";
						document.getElementById("context-menu").style.position = "absolute";
						document.getElementById("context-menu").style.display = "inline";
						document.getElementById("context-menu").style.left = posx;
						document.getElementById("context-menu").style.top = posy;
					}
					function hideMenu() {
						document.getElementById("context-menu").style.display = "none"; 
					}
				</script>
				<div id="new-folder-bg">
					<div id="new-folder-area">
						<h1 class="new-folder"> New Folder </h1>
						<a onclick="hideNewFolder()" class="new-folder" id="close">x</a>
						<form id="new-folder-form" method="post" action="/'.$_GET["name"]."/".$_GET["folder"].'">
							<input class="new-folder-input" id="new-folder-name" type="text" placeholder="name" name="foldername" required>
							<input type="hidden" value="'.$_GET["folder"].'" name="path">
							<input type="hidden" value="new-folder" name="task">
							<label>Public</label><input  style="display:inline; margin-left: 5px;" class="new-folder-input" type="checkbox" name="share">
							<input onclick="hide-new-folder()" type="submit" id="button-input" class="new-folder-input" value="create">
						</form>
					</div>
				</div>
				
				<div id="upload-bg">
					<div id="upload-area">
						<h1 class="upload"> Upload </h1>
						<a onclick="hideUpload()" class="new-folder" id="close">x</a>
						<form id="upload-form" method="post" action="/'.$_GET["name"]."/".$_GET["folder"].'" enctype="multipart/form-data">
							<input class="upload-input" id="upload-file" type="file" placeholder="file" name="userfile" size=" 500000000" maxlength="100000000000000" required>
							<input type="hidden" value="'.$_GET["folder"].'" name="path">
							<input type="hidden" value="upload" name="task">
							<label>Public</label><input class="upload-input" type="checkbox" name="share">
							<input onclick="hide-upload()" type="submit" id="button-input" class="upload-input" value="upload">
						</form>
					</div>
				</div>
				
				
				<table oncontextmenu="return false" onmousedown="hideMenu()" cellspacing="0" >'.$file_list.'</table>
				
				
				<div id="context-menu" style="display:none">
					<table>
						<tr>
							<td>rename</td>
						</tr>
						<tr>
							<td>delete</td>
						</tr>
						<tr>
							<td>set permissions</td>
						</tr>
					</table>
				</div>';
	
		include("static/footer.html");
}


function get_icon($file){
	if($file[4]=="DIRECTORY"){
		return '<td id="icon">'.get_link($file).'<img src="/static/img/icon_folder.svg" width="30px"></a></td>';
	}else{
		return '<td id="icon">'.get_link($file).'<img src="/static/img/icon_file.svg" width="30px"></a></td>';
	}
}

function get_link($file){
	$slash = (($_GET["folder"]!="" && substr($_GET["folder"], -1) != "/"))? "/" : "";
	return '<a oncontextmenu="showMenu(event)" class="file" href="/'.$_GET["name"]."/".$_GET["folder"].$slash.$file[3].'/">';
}

function get_item($file){
	return '<tr>'.get_icon($file).'<td>'.get_link($file).$file[3].'</a></td></tr>';
}

function print_menu(){
	echo '<div id="menu">
	<div class="menu-item"  title="Create Folder" id="new-item" onclick="showNewFolder()" ><i class="fa fa-folder fa-3x" onclick="showNewFolder()"></i></div>
	<div class="menu-item" title="Upload" id="upload-item" onclick="showUpload()" ><i class="fa fa-upload fa-3x" onclick="showUpload()" ></i></div>
	<div class="menu-item" title="Logout" id="logout-item"><a class="logout-item-link" href="/logout"><i class="fa fa-sign-out fa-3x" ></i></a></div>
	</div><!-- div menu-->';
}