<%
local msg = {}
if _SESSION["logined"] ~= nil then

	local admin_nowdir = "/"
	if _SESSION["admin_basefolder"] ~= nil and _SESSION["admin_basefolder"] ~= "" then
		admin_nowdir = _SESSION["admin_basefolder"]
	end

	if _SESSION["admin_nowdir"] ~= nil and _SESSION["admin_nowdir"] ~= "" then
		admin_nowdir = _SESSION["admin_nowdir"]
	end

	local changedir = _POST["dir"] or ""
	local CanChangedir = true
	if _SESSION["admin_basefolder"] ~= nil and _SESSION["admin_basefolder"] ~= "" then
		if c_StringLength(changedir) < c_StringLength(_SESSION["admin_basefolder"]) then
			CanChangedir = false
		end
	end

	if changedir ~= "" and c_IsDir(changedir) == true and CanChangedir == true and c_GetDir(changedir) ~= nil then
		if _SESSION["admin_readonly"] ~= nil and _SESSION["admin_readonly"] == 1 then
		else
			local old_nowpath = admin_nowdir
			admin_nowdir = changedir
			if _SESSION["admin_domainadmin"] ~= nil and _SESSION["admin_domainadmin"] == 1 then
				if c_StringFind(changedir.gsub(changedir,"//", "/").."/", c_GetAppPath() ) > -1 then
					admin_nowdir = old_nowpath
				end
			end
			local nowpath = string.gsub(admin_nowdir,"%[",":{{")
			nowpath = string.gsub(nowpath,"%]","}}:")
			rawset(_SESSION,"admin_nowdir",nowpath)
			SessionModule.save(_SESSION_ID)
		end
	end

	local data = {} 
	local dirs = {}
	rawset(data,"nowdir",admin_nowdir)

	if admin_nowdir == "/" then
		for _,root in pairs(c_GetRootDir()) do
			if root ~= nil and root["isdir"] == true then
				local dir = {}
				rawset(dir,"name",root["dir"])
				rawset(dir,"isdir", true)
				table.insert(dirs,dir)
			end
		end
	else
		if _SESSION["admin_readonly"] ~= nil and _SESSION["admin_readonly"] == 1 then
		else
			for isdir,child in c_GetFileDir(admin_nowdir) do
				if child ~= nil and child ~= "." and child ~= ".." then
					local dir = {}
					rawset(dir,"name",child)
					rawset(dir,"isdir",isdir)
					table.insert(dirs,dir)
				end
			end
		end
	end

	rawset(data,"dirs",dirs)
	rawset(msg,"data",data)
	rawset(msg, "code", 0)
	print(json.encode(msg))
else
	rawset(msg, "code", -1)
	rawset(msg, "error", "Not logged in")
	print(json.encode(msg))
end	
%>