Browse Source

Upload files to 'Photo'

Yeung Alan 5 years ago
parent
commit
ca6315318f

+ 16 - 0
Photo/FloatWindow.php

@@ -0,0 +1,16 @@
+<?php
+include_once("../auth.php");
+
+?>
+<html>
+<head>
+<script src="../script/FloatWindow.js"></script>
+<script>
+var fw = new FloatWindow("index.php?mode=fw","Audio","music", (new Date().getTime()),1050,700,undefined,undefined,true,true);
+fw.launch();
+</script>
+</head>
+<body>
+Starting FloatWindow...
+</body>
+</html>

+ 221 - 0
Photo/Image_manager.js

@@ -0,0 +1,221 @@
+//Image Manager Control Script
+//Global Variables
+var csdirectory = "";//Current Selected Directory
+var previewMode = true;
+var sendmode = 0;
+var selectedFiles = [];
+//SendMode define the mode to move files.
+// 0 - Do not sent
+// 1 - Sent only selected
+// 2 - Sent All
+// 3 - Delete Selected
+$( document ).ready(function() {
+	//Hide the notification bar
+    $('#nfb').hide();
+	//Hide the confirm box
+	$('#confirmbox').hide();
+	//Enable Preview mode as default
+	$("#btn1").attr('class','ts button active');
+	//Unselect all checkbox to prevent browser memory.
+	toggleFalse();
+});
+
+//Check if the foldername contain illegal characters
+$('#fileNameInput').on('input',function(e){
+	$('#fileNameInput').val($('#fileNameInput').val().replace(/[^A-Za-z0-9]/g, ""));
+});
+
+//Check if the user confirm folder creation
+$("#fileNameInput").on('keyup', function (e) {
+    if (e.keyCode == 13) {
+		if ($('#fileNameInput').val() != ""){
+        $.ajax({
+			data: 'name=' + $('#fileNameInput').val(),
+			url: 'new_folder.php',
+			method: 'POST', // or GET
+			success: function(msg) {
+				console.log(msg);
+				if (msg == "DONE"){
+					location.reload(); 
+				}else{
+					showNotifiy("Something went wrong on the server side :(");
+				}
+			}
+		});
+		}else{
+			$('#filenamer').fadeOut('fast');
+		}
+    }
+});
+
+
+
+//Management finished
+function done(){
+	$("body").fadeOut(1000,function(){
+       window.location.href = "index.php";
+    })
+}
+
+//Starting a new folder
+function newfolder(){
+	$('#filenamer').show();
+	$('#fileNameInput').focus();
+	showNotifiy('Enter the folder name and press Enter to create new folder.');
+}
+
+//Check all checkbox
+function toggle() {
+  checkboxes = document.getElementsByName('box2check');
+  for(var i=0, n=checkboxes.length;i<n;i++) {
+    checkboxes[i].checked = true;
+  }
+}
+
+//Uncheck all checkbox
+function toggleFalse() {
+  checkboxes = document.getElementsByName('box2check');
+  for(var i=0, n=checkboxes.length;i<n;i++) {
+    checkboxes[i].checked = false;
+  }
+}
+
+function ConfirmAction(){
+	$('#confirmbox').fadeOut('slow');
+	if (selectedFiles.length != 0 && sendmode != 0){
+		//There are action and files prepared to be sent
+		$.ajax({
+			data: 'files=' + selectedFiles + '&opr=' + sendmode + '&dir=' + csdirectory,
+			url: 'Image_mover.php',
+			method: 'POST', // or GET
+			success: function(msg) {
+				console.log(msg);
+				if (msg == "DONE"){
+					location.reload(); 
+				}else{
+					showNotifiy("Something went wrong on the server side :(");
+				}
+			}
+		});
+		
+		
+	}
+	
+}
+
+function MoveFile(mode){
+	$('#confirmbox').css('background', 'rgba(0,0,0,0.7)');
+	if (csdirectory == "" && mode != 3){
+		//No selected folder target 
+		showNotifiy("No target folder selected.");
+	}else{
+		$('#confirmbox').fadeIn('slow');
+		var msg = "Error. Please refresh this page."
+		sendmode = mode;
+		if (mode == 1){
+			//Get all the checked ids
+			var all, checked, notChecked;
+			all = $("input:checkbox");
+			checked = all.filter(":checked");
+			notChecked = all.not(":checked");
+			var checkedIds = checked.map(function() {
+				return this.id;
+			});
+			msg = "Are you sure that you want to sent the these files to '" + csdirectory +"' ? <br> This process cannot be undo. List of files to be moved:<br>";
+			selectedFiles = [];
+			for (var i = 0, len = checkedIds.length; i < len; i++){
+				//console.log(GetFileNameFromID(checkedIds[i]));
+				var filename = GetFileNameFromID(checkedIds[i]);
+				msg += filename + " -> " + filename.replace("uploads/",csdirectory + "/") + "<br>";
+				selectedFiles.push(filename);
+			}
+			console.log(selectedFiles);
+		}else if (mode == 2){
+			var all, checked, notChecked;
+			all = $("input:checkbox");
+			var Ids = all.map(function() {
+				return this.id;
+			});
+			msg = "All files under 'Unsorted' will be moved to '" + csdirectory + "'. Are you sure?<br> This process cannot be undo. List of files to be moved:<br>";
+			selectedFiles = [];
+			for (var i = 0, len = Ids.length; i < len; i++){
+				//console.log(GetFileNameFromID(checkedIds[i]));
+				var filename = GetFileNameFromID(Ids[i]);
+				msg += filename + " -> " + filename.replace("uploads/",csdirectory + "/") + "<br>";
+				selectedFiles.push(filename);
+			}
+			
+		} else if (mode == 3){
+			$('#confirmbox').css('background', 'rgba(124,66,70,0.8)'); //DARKER:rgba(84,44,47,0.7)
+			var all, checked, notChecked;
+			all = $("input:checkbox");
+			checked = all.filter(":checked");
+			notChecked = all.not(":checked");
+			var checkedIds = checked.map(function() {
+				return this.id;
+			});
+			msg = "All selected files will be DELETED. Are you sure?<br> This process cannot be undo. List of files TO BE DELETED:<br>";
+			selectedFiles = [];
+			for (var i = 0, len = checkedIds.length; i < len; i++){
+				//console.log(GetFileNameFromID(checkedIds[i]));
+				var filename = GetFileNameFromID(checkedIds[i]);
+				msg += "[REMOVE] " + filename + "<br>";
+				selectedFiles.push(filename);
+			}
+			
+		}
+		$('#confirminfo').html(msg);
+	}
+}
+
+
+function GetFileNameFromID(divid){
+	return $("#" + divid + "-rfp").html();
+}
+
+function TogglePreview(){
+	if (previewMode == true){
+		$("#btn1").attr('class','ts button');
+		showNotifiy("Preview Mode Disabled.");
+		previewMode = false;
+		$("#previewWindow").attr("src","img/Photo_manager.png");
+	}else{
+		$("#btn1").attr('class','ts button active');
+		showNotifiy("Preview Mode Enabled.");
+		previewMode = true;
+	}
+}
+
+//Show preview if clicked
+function showPreview(divid){
+	if (previewMode == true){
+		var src = $("#" + divid + "-rfp").html();
+		$("#previewWindow").attr("src",src);
+		if($("#" + divid + "-rfp").length == 0) {
+		  console.log('DIV NOT FOUND');
+		}
+		
+	}
+	//Update other information
+	$('#ImageName').html($("#" + divid + "-ofn").html() + "." + $("#" + divid + "-ext").html());
+	$('#fileext').html($("#" + divid + "-ext").html());
+	$('#storagename').html($("#" + divid + "-rfp").html());
+	$('#imgsize').html($("#" + divid + "-size").html());
+	//$('#targetdir').html($("#" + divid + "-rfp").html());
+}
+
+//Change active focus of folder
+function selectFolder(foldername){
+	$("#" + foldername).attr('class','item active');
+	if (csdirectory != ""){
+		$("#" + csdirectory).attr('class','item');
+	}
+	csdirectory = foldername;
+	$('#targetdir').html(foldername);
+}
+
+//Simple function for poping out the notification bar
+function showNotifiy(text){
+	$('#nfbtxt').html(text);
+	$('#nfb').stop().fadeIn('slow').delay(2000).fadeOut('slow');
+}

+ 398 - 0
Photo/Image_manager.php

@@ -0,0 +1,398 @@
+<?php
+include '../auth.php';
+if(isset($_GET["bkend"])){
+	if(isset($_GET["query"])){
+		if($_GET["query"] == "playlist"){
+			$intdirs = array_filter(glob("storage/" . "*"), 'is_dir');
+			$IntDirWInfo = [];
+			foreach ($intdirs as &$intdir) {
+				preg_match('/storage\/([^\/]*)/', $intdir, $out_storage);
+				$tmp = [];
+				$tmp["name"] = "Internal - ".hex2bin($out_storage[1]);
+				$tmp["dir"] = "../../../Photo/".$intdir."/";
+				$tmp["drive"] = "internal";
+				$tmp["storage"] = $out_storage[1];
+				array_push($IntDirWInfo,$tmp);
+			}
+			if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+				$ExtDirWInfo = []; //TODO: add ext support
+			}else{
+				if (file_exists("/media/")){
+					$extdirs = array_filter(glob("/media/*/Photo/*"), 'is_dir');
+					$ExtDirWInfo = [];
+					foreach ($extdirs as &$extdir) {
+						preg_match('/\/media\/([^\/]*)\//', $extdir, $out_storage);
+						preg_match('/Photo\/([^\/]*)/', $extdir, $out_storage);
+						$tmp = [];
+						$tmp["name"] = $out_storage[1]." - ".hex2bin($out_storage[1]);
+						$tmp["dir"] = $extdir."/";
+						$tmp["drive"] = $out_storage[1];
+						$tmp["storage"] = $out_storage[1];
+						array_push($ExtDirWInfo,$tmp);
+					}
+				}
+			}
+			$dirs = array_merge($IntDirWInfo,$ExtDirWInfo);
+			echo json_encode($dirs);
+		}else if($_GET["query"] == "storage"){
+			$extdirs = array_filter(glob("/media/*"), 'is_dir');
+			$dirs = array_merge($extdirs,["internal"]);
+			echo json_encode($dirs);
+		}else if($_GET["query"] == "unsort"){
+			$intdirs = glob('uploads/*.{jpg,jpeg,png,gif}', GLOB_BRACE);
+			$IntDirWInfo = [];
+			foreach ($intdirs as &$intdir) {
+				$tmp = [];
+				$tmp["dir"] = "../../../Photo/".$intdir;
+				$tmp["drive"] = "internal";
+				array_push($IntDirWInfo,$tmp);
+			}
+			if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+				$ExtDirWInfo = []; //TODO: add ext support
+			}else{
+				if (file_exists("/media/")){
+					$extdirs = glob("/media/*/Photo/*.{jpg,jpeg,png,gif}");
+					$ExtDirWInfo = [];
+					foreach ($extdirs as &$extdir) {
+						preg_match('/\/media\/([^\/]*)\//', $extdir, $out_storage);
+						$tmp = [];
+						$tmp["dir"] = $extdir;
+						$tmp["drive"] = $out_storage[1];
+						array_push($ExtDirWInfo,$tmp);
+					}
+				}
+			}
+			$dirs = array_merge($IntDirWInfo,$ExtDirWInfo);
+			echo json_encode($dirs);
+		}
+	}
+	die();
+}
+?>
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="UTF-8">
+	<script src="../script/jquery.min.js"></script>
+    <link rel="stylesheet" href="../script/tocas/tocas.css">
+	<script type='text/javascript' src="../script/tocas/tocas.js"></script>
+	<script type='text/javascript' src="../script/ao_module.js"></script>
+	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+	<title>ArOZ Onlineβ</title>
+	<style>
+		body{
+			background:rgba(245,245,245,0.8);
+		}
+		@media (max-width: 767px){
+			.ts.bottom.right.snackbar.active{
+				width: 100% !important;
+				bottom: 0px !important;
+				right: 0px !important;
+			}
+		}
+	</style>
+</head>
+<body>
+<nav class="ts attached borderless small menu">
+            <a id="rtiBtn" href="index.php" class="item"><i class="angle left icon"></i></a>
+            <a href="" class="item">ArOZ Photo</a>
+            <div class="right menu">
+				<a onclick="ts('#AddstorageModal').modal('show')" class="item"><i class="add outline icon"></i></a>
+		    	<a href="../Upload Manager/upload_interface.php?target=Photo&filetype=jpg,jpeg,png,gif" class="item"><i class="upload icon"></i></a>
+			    <a href="Image_manager.php" class="item"><i class="folder open outline icon"></i></a>
+            </div>
+</nav>
+<br>
+<div class="ts container">
+<div class="ts inverted segment">
+	<p>Batch moving :
+	<select class="ts basic dropdown" name="batchfolderdropdown">
+		<option>Select</option>
+	</select>
+	<button name="batchfolderbutton" class="ts button"><i class="move icon"></i>Move</button>
+	</p>
+</div>
+
+	<div class="ts grid" id="unsortlist">
+
+	</div>
+</div>
+
+<div class="ts modals dimmer">
+	<dialog id="AddstorageModal" class="ts fullscreen modal" open>
+		<div class="header">
+			Create new storage
+		</div>
+		<div class="content">
+			<div class="ts form">
+			    <div class="field">
+					<label>Storage</label>
+					<select name="storagedropdown">
+						<option>Select</option>
+					</select>
+				</div>
+				<div class="field">
+					<label>New storage name</label>
+					<input type="text" id="storagename">
+					<small></small>
+				</div>
+			</div>
+		</div>
+		<div class="actions">
+			<button class="ts deny button">
+				Cancel
+			</button>
+			<button class="ts positive button" onclick="submit()">
+				Confirm
+			</button>
+		</div>
+	</dialog>
+</div>
+<br><br><br><br>
+<div class="ts bottom right snackbar">
+    <div class="content"></div>
+</div>
+<script>
+//Bind enter key to the input bar
+$("#storagename").on("keydown",function(e){
+	if (e.keyCode == 13){
+		submit();
+	}
+});
+
+//first script to run
+$.ajax({url: "Image_manager.php?bkend=true&query=unsort", success: function(result){
+	var resultArr = JSON.parse(result);
+	var allfile = "";
+	$.each(resultArr, function( index, value ) {
+		if(value["drive"] !== "internal"){
+			var drivename = '<div class="ts horizontal right floated label"><i class="usb icon"></i>' + value["drive"] + '</div>';
+		}else{
+			var drivename = '';
+		}
+		$("#unsortlist").append('<div class="four wide column" id="' + value["dir"] + '"><div class="ts card" style="height:100%"><div class="image"><img src="AOB' + value["dir"] + '"><div class="header"><div class="sub header">' + ao_module_codec.decodeUmFilename(value["dir"].replace(/^.*[\\\/]/, '')) + drivename + '</div></div></div><div class="content"><p><i class="move icon"></i>Move to <select class="ts basic dropdown" name="folderdropdown" file="' + value["dir"] + '" storage="' + value["drive"] + '"><option>Select</option></select></p><button name="deletefile"  file="' + value["dir"] + '" class="ts mini very compact negative button"><i class="delete icon"></i>Delete</button></div></div></div>');
+		allfile += value["dir"] + ",";
+	});
+	$("select[name='batchfolderdropdown']").attr("file",allfile.substr(0,allfile.length -1));
+	step2();
+}});
+
+function step2(){
+	$.ajax({url: "Image_manager.php?bkend=true&query=playlist", success: function(result){
+		var resultArr = JSON.parse(result);
+		$("select[name='folderdropdown']").html("");
+		$("select[name='folderdropdown']").append(new Option("Select",""));
+		
+		$("select[name='batchfolderdropdown']").html("");
+		$("select[name='batchfolderdropdown']").append(new Option("Select",""));		
+		$.each(resultArr, function( index, value ) {
+			$("select[name='folderdropdown'][storage='" + value["drive"] + "']").append(new Option(value["name"],value["dir"]));
+			$("select[name='batchfolderdropdown']").append(new Option(value["name"],value["dir"]));
+		});
+		
+		step3();
+	}});
+}
+
+function step3(){
+	$.ajax({url: "Image_manager.php?bkend=true&query=storage", success: function(result){
+		var resultArr = JSON.parse(result);
+		$("select[name='storagedropdown']").html("");
+		$("select[name='storagedropdown']").append(new Option("Select",""));
+		$.each(resultArr, function( index, value ) {
+			$("select[name='storagedropdown']").append(new Option(value,value));
+		});
+	}});
+	
+	step4();
+}
+
+function step4(){
+	$( "button[name='batchfolderbutton']" ).click(function() {
+		var Arr = $("select[name='batchfolderdropdown']").attr("file").split(",");
+		var DOM = $("select[name='batchfolderdropdown']");
+		
+		var length = Arr.length;
+		var success = 0;
+		var failed = 0;
+		
+		$.each(Arr, function( index, value ) {
+			if(value!== ""){
+				$(DOM).parent().parent().parent().append('<div class="ts active inverted dimmer"><div class="ts text loader" id="processingtext">Processing...</div></div>');
+				$.get( "../SystemAOB/functions/file_system/fsexec.php?opr=move&from=" + value + "&target=" + $(DOM).val() + value.replace(/^.*[\\\/]/, ''), function(UUID) {
+					//Return an UUID, can call fsexec.php?listen={uuid} to see the file moving progress
+					if(!UUID.includes("ERROR")){
+						var timer = setInterval(function(){ 
+							$.get( '../SystemAOB/functions/file_system/fsexec.php?listen=["' + UUID + '"]', function(data) {
+								if(data[0][1] == "done"){
+									success += 1;
+									if(success == length){
+										$("#unsortlist").html('<div class="ts card"><div class="ts slate accordion item"><i class="notice circle icon"></i><span class="header">No file unsorted</span><span class="description">Upload some files to here :)</span></div></div>');
+										$(DOM).parent().parent().parent().find(".ts.active.inverted.dimmer").remove();
+									}
+									if((success + failed) == length){
+										location.reload();
+									}
+									msgbox("Moved " + value.replace(/^.*[\\\/]/, ''));
+									clearInterval(timer);
+								}else if(data[0][1] == "error"){
+									failed += 1;
+									if((success + failed) == length){
+										location.reload();
+									}
+									msgbox("Error moving " + value.replace(/^.*[\\\/]/, ''));
+									clearInterval(timer);
+								}
+							});
+						}, 3000);
+					}else{
+						failed += 1;
+						if((success + failed) == length){
+							location.reload();
+						}
+						msgbox(UUID);
+					}
+				});
+			}
+		});
+	});
+	
+	$( "select[name='folderdropdown']" ).change(function() {
+		if($(this).val()!==""){
+			var DOM = $(this);
+			$(DOM).parent().parent().parent().append('<div class="ts active inverted dimmer"><div class="ts text loader">Processing...</div></div>');
+			$.get( "../SystemAOB/functions/file_system/fsexec.php?opr=move&from=" + $(this).attr("file") + "&target=" + $(this).val() + $(this).attr("file").replace(/^.*[\\\/]/, ''), function(UUID) {
+				//Return an UUID, can call fsexec.php?listen={uuid} to see the file moving progress
+				if(!UUID.includes("ERROR")){
+					var timer = setInterval(function(){ 
+						$.get( '../SystemAOB/functions/file_system/fsexec.php?listen=["' + UUID + '"]', function(data) {
+							if(data[0][1] == "done"){
+								$(DOM).parent().parent().parent().parent().fadeOut( "slow", function() {
+									$(DOM).parent().parent().parent().parent().remove();
+									if($.trim($("#unsortlist").html()) == ""){
+										$("#unsortlist").html('<div class="ts card"><div class="ts slate accordion item"><i class="notice circle icon"></i><span class="header">No file unsorted</span><span class="description">Upload some files to here :)</span></div></div>');
+									}
+								});
+								$(DOM).parent().parent().parent().find(".ts.active.inverted.dimmer").remove();
+								msgbox("Success moving " + $(DOM).attr("file").replace(/^.*[\\\/]/, ''));
+								clearInterval(timer);
+							}else if(data[0][1] == "error"){
+								$(DOM).parent().parent().parent().find(".ts.active.inverted.dimmer").remove();
+								msgbox("Error moving " + $(DOM).attr("file").replace(/^.*[\\\/]/, ''));
+								clearInterval(timer);
+							}
+						});
+					}, 3000);
+				}else{
+					$(DOM).parent().parent().parent().find(".ts.active.inverted.dimmer").remove();
+					msgbox(UUID);
+				}
+			});
+			
+			/*
+			$.post( "mover.php", { opr: 1, files: $(this).attr("file"), dir: $(this).val() },function( data ) {
+				if(data == "DONE"){
+					$(DOM).parent().parent().parent().parent().parent().fadeOut( "slow", function() {
+						$(DOM).parent().parent().parent().parent().parent().remove();
+						if($.trim($("#unsortlist").html()) == ""){
+							$("#unsortlist").html('<div class="ts slate accordion item"><i class="notice circle icon"></i><span class="header">No file unsorted</span><span class="description">Upload some files to here :)</span></div>');
+						}
+					});
+					msgbox("Finished.");
+				}else{
+					msgbox("Error.");
+				}
+			});
+			*/
+		}
+	});
+
+	$( "button[name='deletefile']" ).click(function() {
+		var DOM = $(this);
+		$.post( "mover.php", { opr: 3, files: $(this).attr("file")},function( data ) {
+			if(data == "DONE"){
+				$(DOM).parent().parent().parent().parent().parent().fadeOut( "slow", function() {
+					$(DOM).parent().parent().parent().parent().parent().remove();
+					if($.trim($("#unsortlist").html()) == ""){
+						$("#unsortlist").html('<div class="ts card"><div class="ts slate accordion item"><i class="notice circle icon"></i><span class="header">No file unsorted</span><span class="description">Upload some files to here :)</span></div></div>');
+					}
+				});
+				msgbox("Finished.");
+			}else{
+				msgbox("Error.");
+			}
+		});
+	});
+
+	$( "details" ).click(function() {
+		$("details[open='']").not(this).removeAttr('open');
+	});
+
+	$( ".ts.accordion.item" ).hover(function() {
+		$(".ts.accordion.item").not(this).removeAttr('style');
+		$(this).attr('style',"background-color:#f7f7f7");
+	});
+	
+	if($.trim($("#unsortlist").html()) == ""){
+		$("#unsortlist").html('<div class="ts card"><div class="ts slate accordion item"><i class="notice circle icon"></i><span class="header">No file unsorted</span><span class="description">Upload some files to here :)</span></div></div>');
+	}
+}
+
+/*
+    var OldArr = [];
+    var firstInitOldArr = true;
+	setInterval(function(){ 
+		var notmatch = false;
+		$.ajax({url: "Image_manager.php?bkend=true&query=unsort", success: function(result){
+			var resultArr = JSON.parse(result);
+    		if(resultArr.length !== OldArr.length){
+    			 notmatch = true;
+    		}else{
+        		for (var i = 0; resultArr.length < i; i++) {
+        			if (resultArr[i] !== oldArr[i]){
+        				notmatch = true;
+        			}
+        		}
+    		}
+    		if(firstInitOldArr){
+    		    firstInitOldArr = false;
+    		    notmatch = false;
+    		}
+    		if(notmatch){
+    		   	location.reload();
+    		 }
+    		 OldArr = resultArr;
+		}
+		});
+	}, 3000);
+*/
+	
+function submit(){
+	if(storage = $("select[name='storagedropdown']").val() !== ""){
+		var storage = $("select[name='storagedropdown']").val() + "/";
+		if(storage == "internal/"){
+			storage = "storage/";
+		}
+		$.post( "new_folder.php", { storage: storage, name : $("#storagename").val() },function( data ) {
+			if(data == "DONE"){
+				msgbox("Finished.");
+				location.reload();
+			}
+		});
+	}else{
+		msgbox("You must select the directory.");
+	}
+}
+
+function msgbox(content,bgcolor,fontcolor){
+	$(".snackbar").attr("style",'background-color: ' + bgcolor + ';color:' + fontcolor);
+	ts('.snackbar').snackbar({
+		content: content,
+		onAction: () => {
+			$(".snackbar").removeAttr("style");
+		}
+	});
+}
+</script>
+</body>
+</html>

+ 20 - 0
Photo/Image_mover.php

@@ -0,0 +1,20 @@
+<?php
+include '../auth.php';
+?>
+<?php
+//Image Processing System
+$storage = "storage/";
+$files = explode(",",$_POST['files']);
+$target = $_POST['dir'];
+$opr = $_POST['opr'];
+foreach ($files as $file){
+	if ($opr == 1 || $opr == 2){
+	//No idea why php rename does the moving job =w=
+		rename($file, str_replace('uploads','storage/' .$target,$file));	
+	}
+	if ($opr == 3){
+		unlink($file);
+	}
+}
+echo 'DONE';
+?>

+ 38 - 0
Photo/README.txt

@@ -0,0 +1,38 @@
+
+  _____  _           _           _____ _        _   _             
+ |  __ \| |         | |         / ____| |      | | (_)            
+ | |__) | |__   ___ | |_ ___   | (___ | |_ __ _| |_ _  ___  _ __  
+ |  ___/| '_ \ / _ \| __/ _ \   \___ \| __/ _` | __| |/ _ \| '_ \ 
+ | |    | | | | (_) | || (_) |  ____) | || (_| | |_| | (_) | | | |
+ |_|    |_| |_|\___/ \__\___/  |_____/ \__\__,_|\__|_|\___/|_| |_|
+                                                                  
+                                                                  
+=================================================================
+Standard Photo Station - ArOZ Online BETA Standard Functional Module
+
+# Introduction
+The Photo Station allow user to view image uploaded to the system.
+Photo Station support folder sorting and filename sorting. And this
+is just a simple system that show you image store in this module.
+
+# Functions
+1. View Photos
+2. Download Photos
+3. Upload Photos (via ArOZ Online BETA Upload Manager)
+4. Sort Photos into different directory
+5. Support jpg,jpeg,gif and png
+
+# API
+The photo station provide extremely simple API for applying custom
+search, sorting and folder viewing.
+
+The API has the following format:
+Photo/index.php?folder=folder_name&search=keyword&sort=mode
+
+folder_name is the name of the directory for image scanning
+keyword is the keyword for searching the image. (in string, not hex code)
+mode is the sorting mode used. Left empty for filename in ascending order,
+set to "reverse" for descending order.
+
+(C)IMUS Laboratory 2016-2017
+Licensed under MIT

+ 1 - 0
Photo/description.txt

@@ -0,0 +1 @@
+The Photo function allow you to view and share image directly from your host to your mobile devices through Wifi Direct or local area netwrok. Powered by ArOZ Online ALPHA.

+ 47 - 0
Photo/embedded.php

@@ -0,0 +1,47 @@
+<?php
+include '../auth.php';
+?>
+<html>
+<head>
+<title>Image Viewer</title>
+<script src="../script/jquery.min.js"></script>
+<link rel="stylesheet" href="../script/tocas/tocas.css">
+<script type='text/javascript' src="../script/tocas/tocas.js"></script>
+</head>
+<body style="background:rgba(34,34,34,1);overflow:hidden;">
+<img id="display" src="<?php echo $_GET['filepath'];?>" style="object-fit: scale-down !important;max-width:100%;height:98%;"></img>
+
+<script>
+var imageWidth = $('#display').css('width').replace("px","");
+var imageHeight = $('#display').css('height').replace("px","");
+var inVDI = !(!parent.isFunctionBar);
+var displayName = "<?php echo $_GET['filename'];?>";
+$(window).resize(function() {
+    clearTimeout(window.resizedFinished);
+    window.resizedFinished = setTimeout(function(){
+        //Resize finish, adjust the css accordingly
+		adjustImgWidth();
+    }, 100);
+});
+	
+function adjustImgWidth(){
+		var vw = $('#display').width();
+		var sw = $( window ).width();
+		var center = parseInt((sw - vw) / 2);
+		$('#display').css("left",center);
+}
+
+
+$(document).ready(function(){
+	setTimeout(function(){adjustImgWidth();}, 100);
+	if (inVDI){
+		//If it is currently in VDI, force the current window size and resize properties
+		var windowID = $(window.frameElement).parent().attr("id");
+		parent.setWindowIcon(windowID + "","file image outline");
+		parent.changeWindowTitle(windowID + "",displayName);
+	}
+});
+
+</script>
+</body>
+</html>

+ 286 - 0
Photo/genthumb.php

@@ -0,0 +1,286 @@
+<?php
+include '../auth.php';
+?>
+<?php
+
+/*
+Title:      Thumb.php
+URL:        http://github.com/jamiebicknell/Thumb
+Author:     Jamie Bicknell
+Twitter:    @jamiebicknell
+*/
+
+define('THUMB_CACHE',           'cache/');    // Path to cache directory (must be writeable)
+define('THUMB_CACHE_AGE',       86400);         // Duration of cached files in seconds
+define('THUMB_BROWSER_CACHE',   true);          // Browser cache true or false
+define('SHARPEN_MIN',           12);            // Minimum sharpen value
+define('SHARPEN_MAX',           28);            // Maximum sharpen value
+define('ADJUST_ORIENTATION',    true);          // Auto adjust orientation for JPEG true or false
+define('JPEG_QUALITY',          100);           // Quality of generated JPEGs (0 - 100; 100 being best)
+
+$src = isset($_GET['src']) ? $_GET['src'] : false;
+$size = isset($_GET['size']) ? str_replace(array('<', 'x'), '', $_GET['size']) != '' ? $_GET['size'] : 100 : 100;
+$crop = isset($_GET['crop']) ? max(0, min(1, $_GET['crop'])) : 1;
+$trim = isset($_GET['trim']) ? max(0, min(1, $_GET['trim'])) : 0;
+$zoom = isset($_GET['zoom']) ? max(0, min(1, $_GET['zoom'])) : 0;
+$align = isset($_GET['align']) ? $_GET['align'] : false;
+$sharpen = isset($_GET['sharpen']) ? max(0, min(100, $_GET['sharpen'])) : 0;
+$gray = isset($_GET['gray']) ? max(0, min(1, $_GET['gray'])) : 0;
+$ignore = isset($_GET['ignore']) ? max(0, min(1, $_GET['ignore'])) : 0;
+$path = parse_url($src);
+
+if (isset($path['scheme'])) {
+    $base = parse_url('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
+    if (preg_replace('/^www\./i', '', $base['host']) == preg_replace('/^www\./i', '', $path['host'])) {
+        $base = explode('/', preg_replace('/\/+/', '/', $base['path']));
+        $path = explode('/', preg_replace('/\/+/', '/', $path['path']));
+        $temp = $path;
+        $part = count($base);
+        foreach ($base as $k => $v) {
+            if ($v == $path[$k]) {
+                array_shift($temp);
+            } else {
+                if ($part - $k > 1) {
+                    $temp = array_pad($temp, 0 - (count($temp) + ($part - $k) - 1), '..');
+                    break;
+                } else {
+                    $temp[0] = './' . $temp[0];
+                }
+            }
+        }
+        $src = implode('/', $temp);
+    }
+}
+$src = iconv('utf-8','big-5',$src);
+
+if (!extension_loaded('gd')) {
+    die('GD extension is not installed');
+}
+if (!is_writable(THUMB_CACHE)) {
+    die('Cache not writable');
+}
+if (isset($path['scheme']) || !file_exists($src)) {
+    die('File cannot be found'.$src);
+}
+if (!in_array(strtolower(substr(strrchr($src, '.'), 1)), array('gif', 'jpg', 'jpeg', 'png'))) {
+    die('File is not an image');
+}
+
+$file_salt = 'v1.0.5';
+$file_size = filesize($src);
+$file_time = filemtime($src);
+$file_date = gmdate('D, d M Y H:i:s T', $file_time);
+$file_type = strtolower(substr(strrchr($src, '.'), 1));
+$file_hash = md5($file_salt . ($src.$size.$crop.$trim.$zoom.$align.$sharpen.$gray.$ignore) . $file_time);
+$file_temp = THUMB_CACHE . $file_hash . '.img.txt';
+$file_name = basename(substr($src, 0, strrpos($src, '.')) . strtolower(strrchr($src, '.')));
+
+if (!file_exists(THUMB_CACHE . 'index.html')) {
+    touch(THUMB_CACHE . 'index.html');
+}
+if (($fp = fopen(THUMB_CACHE . 'index.html', 'r')) !== false) {
+    if (flock($fp, LOCK_EX)) {
+        if (time() - THUMB_CACHE_AGE > filemtime(THUMB_CACHE . 'index.html')) {
+            $files = glob(THUMB_CACHE . '*.img.txt');
+            if (is_array($files) && count($files) > 0) {
+                foreach ($files as $file) {
+                    if (time() - THUMB_CACHE_AGE > filemtime($file)) {
+                        unlink($file);
+                    }
+                }
+            }
+            touch(THUMB_CACHE . 'index.html');
+        }
+        flock($fp, LOCK_UN);
+    }
+    fclose($fp);
+}
+
+if (THUMB_BROWSER_CACHE && (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH']))) {
+    if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $file_date && $_SERVER['HTTP_IF_NONE_MATCH'] == $file_hash) {
+        header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
+        die();
+    }
+}
+
+if (!file_exists($file_temp)) {
+    list($w0, $h0, $type) = getimagesize($src);
+    $data = file_get_contents($src);
+    if ($ignore && $type == 1) {
+        if (preg_match('/\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)/s', $data)) {
+            header('Content-Type: image/gif');
+            header('Content-Length: ' . $file_size);
+            header('Content-Disposition: inline; filename="' . $file_name . '"');
+            header('Last-Modified: ' . $file_date);
+            header('ETag: ' . $file_hash);
+            header('Accept-Ranges: none');
+            if (THUMB_BROWSER_CACHE) {
+                header('Cache-Control: max-age=604800, must-revalidate');
+                header('Expires: ' . gmdate('D, d M Y H:i:s T', strtotime('+7 days')));
+            } else {
+                header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
+                header('Expires: ' . gmdate('D, d M Y H:i:s T'));
+                header('Pragma: no-cache');
+            }
+            die($data);
+        }
+    }
+    $oi = imagecreatefromstring($data);
+    if (function_exists('exif_read_data') && ADJUST_ORIENTATION && $type == 2) {
+        // I know supressing errors is bad, but calling exif_read_data on invalid
+        // or corrupted data returns a fatal error and there's no way to validate
+        // the EXIF data before calling the function.
+        $exif = @exif_read_data($src, EXIF);
+        if (isset($exif['Orientation'])) {
+            $degree = 0;
+            $mirror = false;
+            switch ($exif['Orientation']) {
+                case 2:
+                    $mirror = true;
+                    break;
+                case 3:
+                    $degree = 180;
+                    break;
+                case 4:
+                    $degree = 180;
+                    $mirror = true;
+                    break;
+                case 5:
+                    $degree = 270;
+                    $mirror = true;
+                    $w0 ^= $h0 ^= $w0 ^= $h0;
+                    break;
+                case 6:
+                    $degree = 270;
+                    $w0 ^= $h0 ^= $w0 ^= $h0;
+                    break;
+                case 7:
+                    $degree = 90;
+                    $mirror = true;
+                    $w0 ^= $h0 ^= $w0 ^= $h0;
+                    break;
+                case 8:
+                    $degree = 90;
+                    $w0 ^= $h0 ^= $w0 ^= $h0;
+                    break;
+            }
+            if ($degree > 0) {
+                $oi = imagerotate($oi, $degree, 0);
+            }
+            if ($mirror) {
+                $nm = $oi;
+                $oi = imagecreatetruecolor($w0, $h0);
+                imagecopyresampled($oi, $nm, 0, 0, $w0 - 1, 0, $w0, $h0, -$w0, $h0);
+                imagedestroy($nm);
+            }
+        }
+    }
+    list($w,$h) = explode('x', str_replace('<', '', $size) . 'x');
+    $w = ($w != '') ? floor(max(8, min(1500, $w))) : '';
+    $h = ($h != '') ? floor(max(8, min(1500, $h))) : '';
+    if (strstr($size, '<')) {
+        $h = $w;
+        $crop = 0;
+        $trim = 1;
+    } elseif (!strstr($size, 'x')) {
+        $h = $w;
+    } elseif ($w == '' || $h == '') {
+        $w = ($w == '') ? ($w0 * $h) / $h0 : $w;
+        $h = ($h == '') ? ($h0 * $w) / $w0 : $h;
+        $crop = 0;
+        $trim = 1;
+    }
+    $trim_w = ($trim) ? 1 : ($w == '') ? 1 : 0;
+    $trim_h = ($trim) ? 1 : ($h == '') ? 1 : 0;
+    if ($crop) {
+        $w1 = (($w0 / $h0) > ($w / $h)) ? floor($w0 * $h / $h0) : $w;
+        $h1 = (($w0 / $h0) < ($w / $h)) ? floor($h0 * $w / $w0) : $h;
+        if (!$zoom) {
+            if ($h0 < $h || $w0 < $w) {
+                $w1 = $w0;
+                $h1 = $h0;
+            }
+        }
+    } else {
+        $w1 = (($w0 / $h0) < ($w / $h)) ? floor($w0 * $h / $h0) : floor($w);
+        $h1 = (($w0 / $h0) > ($w / $h)) ? floor($h0 * $w / $w0) : floor($h);
+        $w = floor($w);
+        $h = floor($h);
+        if (!$zoom) {
+            if ($h0 < $h && $w0 < $w) {
+                $w1 = $w0;
+                $h1 = $h0;
+            }
+        }
+    }
+    $w = ($trim_w) ? (($w0 / $h0) > ($w / $h)) ? min($w, $w1) : $w1 : $w;
+    $h = ($trim_h) ? (($w0 / $h0) < ($w / $h)) ? min($h, $h1) : $h1 : $h;
+    if ($sharpen) {
+        $matrix = array (
+            array(-1, -1, -1),
+            array(-1, SHARPEN_MAX - ($sharpen * (SHARPEN_MAX - SHARPEN_MIN)) / 100, -1),
+            array(-1, -1, -1));
+        $divisor = array_sum(array_map('array_sum', $matrix));
+    }
+    $x = strpos($align, 'l') !== false ? 0 : (strpos($align, 'r') !== false ? $w - $w1 : ($w - $w1) / 2);
+    $y = strpos($align, 't') !== false ? 0 : (strpos($align, 'b') !== false ? $h - $h1 : ($h - $h1) / 2);
+    $im = imagecreatetruecolor($w, $h);
+    $bg = imagecolorallocate($im, 255, 255, 255);
+    imagefill($im, 0, 0, $bg);
+    switch ($type) {
+        case 1:
+            imagecopyresampled($im, $oi, $x, $y, 0, 0, $w1, $h1, $w0, $h0);
+            if ($sharpen && version_compare(PHP_VERSION, '5.1.0', '>=')) {
+                imageconvolution($im, $matrix, $divisor, 0);
+            }
+            if ($gray) {
+                imagefilter($im, IMG_FILTER_GRAYSCALE);
+            }
+            imagegif($im, $file_temp);
+            break;
+        case 2:
+            imagecopyresampled($im, $oi, $x, $y, 0, 0, $w1, $h1, $w0, $h0);
+            if ($sharpen && version_compare(PHP_VERSION, '5.1.0', '>=')) {
+                imageconvolution($im, $matrix, $divisor, 0);
+            }
+            if ($gray) {
+                imagefilter($im, IMG_FILTER_GRAYSCALE);
+            }
+            imagejpeg($im, $file_temp, JPEG_QUALITY);
+            break;
+        case 3:
+            imagefill($im, 0, 0, imagecolorallocatealpha($im, 0, 0, 0, 127));
+            imagesavealpha($im, true);
+            imagealphablending($im, false);
+            imagecopyresampled($im, $oi, $x, $y, 0, 0, $w1, $h1, $w0, $h0);
+            if ($sharpen && version_compare(PHP_VERSION, '5.1.0', '>=')) {
+                $fix = imagecolorat($im, 0, 0);
+                imageconvolution($im, $matrix, $divisor, 0);
+                imagesetpixel($im, 0, 0, $fix);
+            }
+            if ($gray) {
+                imagefilter($im, IMG_FILTER_GRAYSCALE);
+            }
+            imagepng($im, $file_temp);
+            break;
+    }
+    imagedestroy($im);
+    imagedestroy($oi);
+}
+
+header('Content-Type: image/' . $file_type);
+header('Content-Length: ' . filesize($file_temp));
+header('Content-Disposition: inline; filename="' . $file_name . '"');
+header('Last-Modified: ' . $file_date);
+header('ETag: ' . $file_hash);
+header('Accept-Ranges: none');
+if (THUMB_BROWSER_CACHE) {
+    header('Cache-Control: max-age=604800, must-revalidate');
+    header('Expires: ' . gmdate('D, d M Y H:i:s T', strtotime('+7 days')));
+} else {
+    header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
+    header('Expires: ' . gmdate('D, d M Y H:i:s T'));
+    header('Pragma: no-cache');
+}
+
+readfile($file_temp);

+ 352 - 0
Photo/index.js

@@ -0,0 +1,352 @@
+//Photo Station Main Control Javascript for index.php
+	var VDI = ao_module_virtualDesktop;
+	var pwa = $("#DATA_PIPELINE_pwa").text().trim() == "true";
+	if (VDI){
+		//Inside VDI mode, init window properties
+		$("#topMenu").hide();
+		ao_module_setWindowIcon("photo");
+		ao_module_setWindowTitle("ArOZ Photo");
+		ao_module_setGlassEffectMode();
+	}else if (pwa){
+		$("#topMenu").hide();
+		$("#contentFrame").css("padding","3px");
+	}
+	//Injecting variable from PHP using DOM event
+	var folder_path = $("#DATA_PIPELINE_folder_path").text().trim();
+	var search_keyword = $("#DATA_PIPELINE_search_keyword").text().trim();
+	var sort_mode = $("#DATA_PIPELINE_sort_mode").text().trim();
+	var path2name = JSON.parse($("#DATA_PIPELINE_path2name").text().trim());
+	
+	//Global variables
+		var downloadOn = false;
+		var previewmode = false;
+		var screenWidth = 0;
+		var screenHeight = 0;
+		var PreviewWidth = 0;
+		var PreviewHeight = 0;
+		var resizecount = 0;
+		var currentViewingPath = "";
+		/////////////////
+		$(document).ready(function() {
+		  //If there are search result, put it into the search bar
+		  if (search_keyword != ""){
+			$('#searchbar').val(search_keyword);
+		  }
+		  //Update the folder path shown on file explorer (?
+		  if (folder_path != ""){
+				$('#folderdir').html(folder_path);
+		  }else{
+				$('#folderdir').html('Unsorted');
+		  }
+		  //Update Sort Mode
+		  if (sort_mode == ""){
+			  $("#sort1").attr('class', 'ts button active');
+			  $("#sort2").attr('class', 'ts button');
+		  }else if (sort_mode == "reverse"){
+			  $("#sort1").attr('class', 'ts button');
+			  $("#sort2").attr('class', 'ts button active');
+		  }
+		  //Hide the notification bar
+		  $('#nbar').hide();
+		  
+		  //Get Preview Image Size
+		  var img = document.getElementById('previewingImage'); 
+		  PreviewWidth = img.clientWidth;
+		  if (PreviewWidth < $('#previewImageDiv').width()){
+			  PreviewWidth = $('#previewImageDiv').width();
+		  }
+		  
+		  //Get Screen Width
+		  screenWidth = $(window).width();
+		  screenHeight = $(window).height();
+		  centerPreview(screenWidth,PreviewWidth);
+		  
+		  //console.log(path2name);
+		});
+		ts('.ts.dropdown:not(.basic)').dropdown();
+		
+		function uploadImage(){
+			if (pwa){
+				window.open("../Upload Manager/upload_interface.php?target=Photo&filetype=jpg,png,jpeg,gif&finishing=Image_manager.php");
+			}else{
+				window.location.href = "../Upload Manager/upload_interface.php?target=Photo&filetype=jpg,png,jpeg,gif&finishing=Image_manager.php";
+			}
+		}
+		
+		function openImageManager(){
+			if (pwa){
+				window.open("Image_manager.php");
+			}else{
+				window.location.href = "Image_manager.php";
+			}
+		}
+		
+		$(window).resize(function() {
+			var img = document.getElementById('previewingImage'); 
+			PreviewWidth = img.clientWidth;
+			if (PreviewWidth < $('#previewImageDiv').width()){
+			  PreviewWidth = $('#previewImageDiv').width();
+			}
+			PreviewHeight = img.clientHeight;
+			screenWidth = $(window).width();
+			screenHeight = $(window).height();
+			setTimeout(resizeImage, 100);
+			console.log(PreviewWidth,screenWidth);
+			console.log(PreviewHeight,screenHeight);
+		});
+		
+		//Share this page
+		function shareThis(){
+			//alert(window.location.href);
+			var currentHref = window.location.href;
+			if (pwa){
+				window.open("../QuickSend/index.php?share=" + currentHref);
+			}else{
+				window.location.href = "../QuickSend/index.php?share=" + currentHref;
+			}
+			
+		}
+		
+		//Handle document keypress events
+		$(document).keydown(function(e) {
+			  if (e.keyCode == 37){
+				  //Previous Image
+				  if (previewmode == true){
+					  //It is currently previewing and user want to switch to previous image
+					  var viewingCount = GetPosInFileList(currentViewingPath);
+					  TogglePreview(0);
+					  var Path = path2name[viewingCount-1][0];
+					  if (Path != "undefined"){
+						TogglePreview(path2name[viewingCount-1][0]);
+					  }
+				  }
+			  }
+			  if(e.keyCode == 39){
+				  //Next Image
+				  if (previewmode == true){
+					  //It is currently previewing and user want to switch to next image
+					  var viewingCount = GetPosInFileList(currentViewingPath);
+					  TogglePreview(0);
+					  if (Path != "undefined"){
+						TogglePreview(path2name[viewingCount+1][0]);
+					  }
+				  }
+			  }
+		
+		});
+
+		function GetPosInFileList(path){
+			var files = path2name;
+			for(var i = 0; i < files.length;i++){
+				if (files[i][0] == path){
+					return i;
+				}
+			}
+			return -1;
+		}
+		
+		//Load Image to Preview
+		function TogglePreview(imagepath){
+			if (downloadOn == false){
+				var img = document.getElementById('previewingImage'); 
+				if (previewmode == false && imagepath != 0){
+					currentViewingPath = imagepath;
+					//Amazing hack to make the auto resize work :)
+					setTimeout(resizeImage, 100);
+					//Open Preview Window
+					$("#previewingImage").attr('class', 'ts massive image');
+					$('#previewingImage').attr("src", imagepath);
+					$('#imagePreview').fadeIn('fast');
+					var ext = imagepath.split(".").pop();
+					$('#previewImagetxt').html('  <i class="image icon"></i>' + ext + '    <i class="folder open icon"></i>/' + imagepath + '    <i class="external icon"></i><a href="' + imagepath +'" target="_blank">View Raw</a>  <br><p></p>');
+					previewmode = true;
+				}else{
+					//Closing preview mode
+					$('#imagePreview').fadeOut('fast');
+					previewmode = false;
+				}
+			}else{
+				//Download Mode is On
+				var orgname = GetFileName(imagepath)
+				saveAs(imagepath,orgname);
+			}
+		}
+		
+		//Save as specific filename
+		function saveAs(uri, filename) {
+			var link = document.createElement('a');
+			if (typeof link.download === 'string') {
+				document.body.appendChild(link); // Firefox requires the link to be in the body
+				link.download = filename;
+				link.href = uri;
+				link.click();
+				document.body.removeChild(link); // remove the link when done
+			} else {
+				location.replace(uri);
+			}
+		}
+		
+		
+		//Get the real filename from the PHP JSON
+		function GetFileName(filepath){
+			for(var k = 0; k < path2name.length; k++){
+				if(path2name[k][0] == filepath ){
+					return path2name[k][1];
+				}
+			}
+		}
+		
+		//Auto resize handler
+		function resizeImage() {
+			var img = document.getElementById('previewingImage'); 
+			PreviewWidth = img.clientWidth;
+			if (PreviewWidth < $('#previewImageDiv').width()){
+			  PreviewWidth = $('#previewImageDiv').width();
+			}
+			PreviewHeight = img.clientHeight;
+			screenWidth = $(window).width();
+			screenHeight = $(window).height();
+			centerPreview(screenWidth,PreviewWidth);
+			resizecount += 1;
+			if (resizecount < 10){
+				setTimeout(resizeImage, 50);
+			}else{
+				resizecount = 0;
+				if (PreviewHeight > screenHeight - 150){
+					//Change it to a smaller class
+					console.log('Adjusting Image Size');
+					$("#previewingImage").attr('class', 'ts large image');
+					setTimeout(resizeImageTiny, 100);
+				}
+			}
+		}
+		
+		function resizeImageTiny() {
+			var img = document.getElementById('previewingImage'); 
+			PreviewWidth = img.clientWidth;
+			if (PreviewWidth < $('#previewImageDiv').width()){
+			  PreviewWidth = $('#previewImageDiv').width();
+			}	
+			PreviewHeight = img.clientHeight;
+			screenWidth = $(window).width();
+			screenHeight = $(window).height();
+			centerPreview(screenWidth,PreviewWidth);
+			resizecount += 1;
+			if (resizecount < 10){
+				setTimeout(resizeImageTiny, 50);
+			}else{
+				resizecount = 0;
+				if (PreviewHeight > screenHeight){
+					//Change it to a smaller class
+					console.log('Adjusting Image Size');
+					$("#previewingImage").attr('class', 'ts medium image');
+					//setTimeout(SingleImageUpdate, 100);
+				}
+			}
+		}
+		
+		function SingleImageUpdate(){
+			var img = document.getElementById('previewingImage'); 
+			PreviewWidth = img.clientWidth;
+			if (PreviewWidth < $('#previewImageDiv').width()){
+			  PreviewWidth = $('#previewImageDiv').width();
+			}
+			PreviewHeight = img.clientHeight;
+			screenWidth = $(window).width();
+			screenHeight = $(window).height();
+			centerPreview(screenWidth,PreviewWidth);
+		}
+		//Move Preview Image from Left
+		function centerPreview(sw,iw){
+			var offsets = Math.round(sw / 2 - iw / 2);
+			$("#previewImageDiv").css("left", offsets + "px");
+		}
+		
+		
+		//Download Mode
+		function downloadmode(){
+			if (downloadOn == false){
+				//Turn download mode on
+				$('#nbartxt').html('Download Mode Enabled.');
+				$('#nbar').stop().fadeIn('slow').delay(2000).fadeOut('slow');
+				downloadOn = true;
+				$("#dlbtn").attr('class', 'ts button active');
+			}else{
+				//Turn off download mode
+				$('#nbartxt').html('Download Mode Disabled.');
+				$('#nbar').stop().fadeIn('slow').delay(2000).fadeOut('slow');
+				$("#dlbtn").attr('class', 'ts button');
+				downloadOn = false;
+			}
+		}
+		
+		
+		//Switch sorting mode
+		function changeSortMethod(id){
+			var cmd = "";
+			if (folder_path != ""){
+				cmd += "?folder=" + folder_path;
+			}
+			if (search_keyword != ""){
+				if (cmd == ""){
+					cmd += "?search=" + search_keyword;
+				}else{
+					cmd += "&search=" + search_keyword;
+				}
+				
+			}
+			
+			if (pwa){
+				if (cmd.includes("?") == false){
+					cmd += "?pwa=enabled";
+				}else{
+					cmd += "&pwa=enabled";
+				}
+				
+			}
+			if (id == 1){
+				//Change to sort mode
+				window.location = "index.php" + cmd;
+			}else if (id == 2){
+				//Change to rsort mode
+				var pwaSupport = "";
+				if (pwa && window.location.href.includes("pwa") == false){
+					pwaSupport = "&pwa=enabled";
+				}
+				if (cmd == ""){
+					window.location = "index.php?sort=reverse" + pwaSupport;
+				}else{
+					window.location = "index.php" + cmd + "&sort=reverse" + pwaSupport;
+				}
+			}
+		}
+		
+		//Switch viewing folder
+		function changeFolderView(folder_name){
+			if (folder_name != 0){
+				if (pwa){
+					window.location = "index.php?folder=" + folder_name + "&pwa=enabled";
+				}else{
+					window.location = "index.php?folder=" + folder_name;
+				}
+				
+			}else{
+				if (pwa){
+					window.location = "index.php?pwa=enabled";	
+				}else{
+					window.location = "index.php";	
+				}
+				
+			}
+		}
+		//On Search Enter pressed
+		$('#searchbar').on('keydown', function(e) {
+			if (e.which == 13) {
+				e.preventDefault();
+				if (folder_path != ""){
+					window.location = "index.php?folder=" + folder_path + "&search=" + $('#searchbar').val();
+				}else{
+					window.location = "index.php?search=" + $('#searchbar').val();
+				}
+			}
+		});

+ 301 - 0
Photo/index.php

@@ -0,0 +1,301 @@
+<?php
+include '../auth.php';
+?>
+<!DOCTYPE html>
+<meta name="apple-mobile-web-app-capable" content="yes" />
+<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=0.6, maximum-scale=0.6"/>
+<html>
+<head>
+<link rel="manifest" href="manifest.json">
+<script type='text/javascript' charset='utf-8'>
+    // Hides mobile browser's address bar when page is done loading.
+      window.addEventListener('load', function(e) {
+        setTimeout(function() { window.scrollTo(0, 1); }, 1);
+      }, false);
+</script>
+    <meta charset="UTF-8">
+	<script src="../script/jquery.min.js"></script>
+    <link rel="stylesheet" href="../script/tocas/tocas.css">
+	<script type='text/javascript' src="../script/tocas/tocas.js"></script>
+	<script type='text/javascript' src="../script/ao_module.js"></script>
+	<title>ArOZ Onlineβ</title>
+	<style>
+		body{
+			background-color: #f7f7f7;
+		}
+	</style>
+</head>
+<body>
+    <nav id="topMenu" class="ts attached inverted borderless normal menu">
+        <div class="ts narrow container">
+            <a href="../" class="item">ArOZ Onlineβ</a>
+        </div>
+    </nav>
+
+	<!-- Main Header-->
+	<?php
+	//random image selector
+	if (isset($_GET['folder']) && $_GET['folder'] != ""){
+		$folder = $_GET['folder'];
+		$imagesDir = 'storage/' . $folder ."/";
+	}else{
+		$imagesDir = 'uploads/';
+		
+	}
+	if (isset($_GET['filepath']) && $_GET['filename']){
+		header("Location: embedded.php?filename=" . $_GET['filename'] . "&filepath=" . $_GET['filepath']);
+	}
+	$images = glob($imagesDir . '*.{jpg,jpeg,png}', GLOB_BRACE);
+	if (sizeof($images) == 0){
+		array_push($images,'img/std_background.png');
+	}
+	$randomImage = $images[array_rand($images)];
+	//Handle pwa request
+	$pwa = "false";
+	if (isset($_GET['pwa']) && $_GET['pwa'] == "enabled"){
+		$pwa = "true";
+	}
+	?>
+    <div class="ts center aligned borderless attached very padded segment" style="background-image:url(<?php echo $randomImage;?>);background-size: cover; background-position: center; ">
+        <div class="ts narrow container">
+            <br>
+			<div style="background:rgba(0,0,0,0.5);border-radius: 25px;">
+            <div class="ts massive header" style="color:white">
+                Photo Station
+                <div class="sub header" style="color:white">
+                Share your photo with your friends and family
+                </div>
+            </div>
+			</div>
+            <br>
+            <a onClick="uploadImage();" class="ts labeled icon button">
+				<i class="upload icon"></i>
+				Upload
+			</a>
+			<a onClick="openImageManager();" class="ts right labeled icon button">
+				Manage
+				<i class="folder open icon"></i>
+			</a>
+            <br>
+            <br>
+        </div>
+    </div>
+	<div class="ts attached pointing secondary menu">
+		
+		<!-- Dropdown Menu -->
+		<div class="ts dropdown labeled icon button" style="width:200px">
+			<i class="folder icon"></i>
+			<span id="folderdir" class="text">Loading...</span>
+			<div class="menu">
+			<div class="header">
+				<i class="folder open icon"></i> uploads/
+			</div>
+			<?php
+				$dirs = array_filter(glob('storage/*'), 'is_dir');
+				//check if defined folder path
+				if (isset($_GET['folder']) && $_GET['folder'] != ""){
+					$folderpath = $_GET['folder'];
+				}else{
+					$folderpath = "";
+				}
+				
+				//Check if defined search keyword
+				if (isset($_GET['search']) && $_GET['search'] != ""){
+					$keyword = $_GET['search'];
+				}else{
+					$keyword = "";
+				}
+				
+				
+				if ($folderpath == ""){
+					echo '<a class="active item" Onclick="changeFolderView(0)">Unsorted</a>';
+				}else{
+					echo '<a class="item" Onclick="changeFolderView(0)">Unsorted</a>';
+				}
+				echo '<div class="divider"></div>';
+				echo '<div class="header">
+				<i class="folder open icon"></i> storage/
+				</div>';
+				foreach ($dirs as $folder){
+						$folder = str_replace("storage/","",$folder);
+						if ($folderpath == $folder){
+							echo "<a class='active item' Onclick='changeFolderView(".'"' . $folder . '"'.")'>".$folder.'</a>';	
+						}else{
+							echo "<a class='item' Onclick='changeFolderView(".'"' . $folder . '"'.")'>".$folder.'</a>';
+						}
+				}
+			?>
+			</div>
+		</div>
+		<div class="ts icon buttons">
+			<button id="sort1" class="ts button active" Onclick="changeSortMethod(1);"><i class="sort alphabet ascending icon"></i></button>
+			<button id="sort2" class="ts button" Onclick="changeSortMethod(2);"><i class="sort alphabet descending icon"></i></button>
+			<button id="dlbtn" class="ts button" onClick="downloadmode();"><i class="download icon"></i></button>
+			<?php 
+			if (file_exists("../QuickSend/")){
+				echo '<button class="ts button" onClick="shareThis();"><i class="share alternate icon"></i></button>';
+			}else{
+				echo '<button class="ts disabled button"><i class="share alternate icon"></i></button>';
+			}
+			?>
+			<!-- <button class="ts button" onClick="shareThis();"><i class="share alternate icon"></i></button> -->
+		</div>
+		<div class="right fitted item">
+			<div class="ts borderless right icon input">
+				<input id="searchbar" type="text" placeholder="Search...">
+				<i class="search icon"></i>
+			</div>
+		</div>
+    </div>
+
+    <div id="contentFrame" class="ts center aligned attached vertically very padded secondary segment">
+
+        <div class="ts narrow container">
+
+            <div class="ts stackable five flatted cards">
+
+				<?php
+                $template = '<div class="ts card">
+                    <div class="image">
+                        <img src="genthumb.php?src=%FILE_PATH%&size=%3C480" OnClick="TogglePreview('."'".'%IMGAGE_PATH%'."'".')">
+                    </div>
+                    <div class="left aligned content">
+                        <div class="description">%UPLOAD_DATA%</div>
+                    </div>
+                </div>';
+				//Scan all image within dir
+				if (isset($_GET['folder']) && $_GET['folder'] != ""){
+					$files = glob("storage/".$_GET['folder'].'/*.{jpg,jpeg,png,gif}', GLOB_BRACE);
+				}else{
+					$files = glob('uploads/*.{jpg,jpeg,png,gif}', GLOB_BRACE);
+				}
+				
+				//Sort the file accordingly
+				if (isset($_GET['sort']) && $_GET['sort'] != ""){
+					$sortmode = $_GET['sort'];
+					if ($_GET['sort'] = 'reverse'){
+						rsort($files);
+					}
+				}else{
+					$sortmode = "";
+					sort($files);
+				}
+				$count = 0;
+				$path2name = [];
+				foreach($files as $file) {
+					if ($keyword != ""){
+						//There are set keyword for search
+						$ext = pathinfo($file, PATHINFO_EXTENSION);
+						$filename = str_replace("." . $ext,"",str_replace("inith","",basename($file)));
+						$filename = hex2bin($filename);
+						if (strpos(strtolower($filename),strtolower($keyword)) !== False){
+							//echo $file . "<br>";
+							$box = str_replace("%FILE_PATH%",$file,$template);
+							$box = str_replace("%UPLOAD_DATA%",$filename,$box);
+							$box = str_replace("%IMGAGE_PATH%",$file,$box);
+							echo $box;
+							$count += 1;
+							array_push($path2name,[$file,$filename . "." .$ext]);
+						}
+						
+					}else{
+						$ext = pathinfo($file, PATHINFO_EXTENSION);
+						$filename = str_replace("." . $ext,"",str_replace("inith","",basename($file)));
+						$filename = hex2bin($filename);
+						//echo $file . "<br>";
+						$box = str_replace("%FILE_PATH%",$file,$template);
+						$box = str_replace("%UPLOAD_DATA%",$filename,$box);
+						$box = str_replace("%IMGAGE_PATH%",$file,$box);
+						echo $box;
+						$count += 1;
+						array_push($path2name,[$file,$filename. "." .$ext]);
+					}
+				}
+				
+				if ($count == 0){
+					//No result found.
+					$box = str_replace("%FILE_PATH%","img/no_img_found.png",$template);
+					$uploadmsg = "<div align='center'><a class='ts button' onClick='uploadImage();'>Upload</a></div>";
+					$box = str_replace("%IMGAGE_PATH%","img/no_img_found.png",$box);
+					$box = str_replace("%UPLOAD_DATA%",$uploadmsg,$box);
+					echo $box;
+				}
+				?>
+               
+            </div>
+
+        </div>
+
+    </div>
+	
+    <!--Notification Bar -->
+	<div id="nbar" class="ts bottom right active snackbar" style="display:none;">
+		<div id="nbartxt" class="content">
+			Download Mode Enabled.
+		</div>
+		<a class="primary action" Onclick="downloadmode()">Toggle</a>
+	</div>
+	
+	<!-- Image Preview Window -->
+	<div id="imagePreview" align="center" style="z-index: 99; display:none;">
+	<div style="position:fixed;
+    top:0;
+    left:0 !important;;
+    height:100%;
+	width:100%;
+    z-index: 100;
+	background:rgba(0,0,0,0.3);
+	boarder:0px;" OnClick="TogglePreview()">
+	<div class="ts active dimmer"></div>	
+	</div>
+	<!-- Close Button -->
+	<div style="position:fixed;
+	z-index: 101;
+	top:100px;
+	background-color:#383838;
+	top:0;left:0;
+	">
+	<button OnClick="TogglePreview(0);" class="ts big close button"></button>
+	</div>
+	
+	<!-- Preview Image -->
+	<div id="previewImageDiv" align="center" style="position:fixed;
+	z-index: 101;
+	top:70px;
+	left:0;
+	color:white;
+	max-height:100%;
+	//background:rgba(0,0,0,0.5);
+	">
+	<img id="previewingImage" class="ts massive image" src="img/std_background.png"><br>
+	<div id="previewImagetxt" align="center"><i class="image icon"></i>Loading...</div>
+	</div>
+	</div>
+	
+	<!-- Bottom Bar -->
+    <div class="ts bottom attached segment">
+        <div class="ts narrow container">
+            <br>
+            <div class="ts large header">
+                ArOZ Online Beta Photo Station
+                <div class="smaller sub header">
+                    CopyRight IMUS Laboratory, 2016-2017
+                </div>
+            </div>
+            <br>
+        </div>
+    </div>
+	<div id="DATA_PIPELINE_pwa" style="display:none;"><?php echo $pwa;?></div>
+	<div id="DATA_PIPELINE_folder_path" style="display:none;"><?php echo $folderpath;?></div>
+	<div id="DATA_PIPELINE_search_keyword" style="display:none;"><?php echo $keyword;?></div>
+	<div id="DATA_PIPELINE_sort_mode" style="display:none;"><?php echo $sortmode;?></div>
+	<div id="DATA_PIPELINE_path2name" style="display:none;"><?php echo json_encode($path2name); ?></div>
+	<script>
+				
+	</script>
+	<script>
+
+	</script>
+	<script src="index.js"></script>
+</body>
+</html>

+ 22 - 0
Photo/manifest.json

@@ -0,0 +1,22 @@
+{
+  "name": "ArOZ Photo",
+  "short_name": "PhotoA",
+  "icons": [{
+    "src": "img/pwa/128.png",
+      "sizes": "128x128",
+      "type": "image/png"
+    }, {
+      "src": "img/pwa/192.png",
+      "sizes": "192x192",
+      "type": "image/png"
+    }, {
+      "src": "img/pwa/256.png",
+      "sizes": "256x256",
+      "type": "image/png"
+    }],
+  "start_url": "index.php?pwa=enabled",
+  "display": "standalone",
+  "scope": "./",
+  "background_color": "#f7f7f7",
+  "theme_color": "#4286f4"
+}

+ 13 - 0
Photo/new_folder.php

@@ -0,0 +1,13 @@
+<?php
+include '../auth.php';
+?>
+<?php
+//New Folder Creation PHP
+$foldername = $_POST['name'];
+$storage = "storage/";
+
+if (file_exists($storage . $foldername . "/") == false){
+	mkdir($storage . $foldername . "/");
+	echo 'DONE';
+}
+?>