<%
local msg = {}
if _SESSION["logined"] ~= nil then
	if _SESSION["admin_readonly"] ~= nil and _SESSION["admin_readonly"] == 1 then
		rawset(msg, "code", -2)
		rawset(msg, "error", "admin read only")
		print(json.encode(msg))
	else
		local admin_nowpath = "/"
		if _SESSION["admin_nowpath"] ~= nil and _SESSION["admin_nowpath"] ~= "" then
			admin_nowpath = string.gsub(_SESSION["admin_nowpath"],":{{","%[")
			admin_nowpath = string.gsub(admin_nowpath,"}}:","%]")
		end

		local newdir = _POST["dir"]
		if newdir ~= nil and newdir ~= "" then
			local fullpath = admin_nowpath.."/"..newdir

			local CanMakedir = true
			if _SESSION["admin_basefolder"] ~= nil and _SESSION["admin_basefolder"] ~= "" then
				if c_StringLength(fullpath) < c_StringLength(_SESSION["admin_basefolder"]) then
					CanMakedir = false
				else
					if c_StringFind(fullpath, _SESSION["admin_basefolder"]) == -1 then
						CanMakedir = false
					end
				end
			end

			if CanMakedir == true then
				local result = c_MkDir(fullpath)
				if result == true then
					c_AddAdminLog("administrator '".._SESSION["admin"].."' created folder ["..fullpath.."].",ADMIN_LOG_OK)
					rawset(msg, "code", 0)
					print(json.encode(msg))
				else
					c_AddAdminLog("administrator '".._SESSION["admin"].."' can't create folder ["..fullpath.."].",ADMIN_LOG_ERROR)
					rawset(msg, "code", -3)
					rawset(msg, "error", "make directory '["..newdir.."]' failed.")
					print(json.encode(msg))
				end
			else
				rawset(msg, "code", -4)
				rawset(msg, "error", "can not make dir")
				print(json.encode(msg))
			end
		else
			rawset(msg, "code", -5)
			rawset(msg, "error", "empty dir")
			print(json.encode(msg))
		end
	end
else
	rawset(msg, "code", -1)
	rawset(msg, "error", "not logged in")
	print(json.encode(msg))
end
%>