$templates.shared.doctype
{=
include "templates.shared.util.convert_name_to_integer_string";
subroutine(encode_display(string the_string), (
the_string = replace_all(the_string, "$", "$");
the_string;
));
string pathname_request;
string invalid_pathname;
bool path_is_valid = false;
bool pathname_request_is_file = false;
bool show_path_not_found_alert = false;
# clean file info node
if (node_exists("volatile.file_info")) then (
delete_node("volatile.file_info");
);
# if this is a request with a defined pathname
if (node_exists("volatile.pathname_request")) then (
pathname_request = volatile.pathname_request;
# decode the pathname string
# pathname_request = decode_pathname(pathname_request);
debug_message("\n\n#### pathname request (encoded): " . pathname_request . "\n");
# -----------------------
# decode pathname_request
# -----------------------
if (node_exists("volatile.dat")) then (
delete_node("volatile.dat");
);
split(pathname_request, "-", "volatile.dat");
pathname_request = "";
node item;
foreach item "volatile.dat" (
pathname_request .= ascii_to_char(node_value(item));
);
debug_message("\n\n#### pathname request (decoded): " . pathname_request . "\n");
# ----------------------
# check if path is valid
# ----------------------
path_is_valid = file_exists(pathname_request);
debug_message("#### pathname request (decoded): " . pathname_request . "\n");
debug_message("#### path is valid: " . path_is_valid . "\n");
if (path_is_valid) then (
get_file_info(pathname_request, "volatile.file_info");
node file_info = "volatile.file_info";
debug_message("\n\nfile_info:\n" . node_as_string(file_info) . "\n\n");
string type = node_value(subnode_by_name(file_info, "type"));
debug_message("pathname_request: " . replace_all(pathname_request, '$', 'DOLLAR') . "\n");
debug_message("file exists: " . path_is_valid . "\n");
if (type eq "file") then (
pathname_request_is_file = true;
pathname_request = node_value(subnode_by_name(file_info, "parent"));
);
# get the parent of the pathname_request which is used to move the directory one level up
# get new "file info" because the pathname_request could have been modified above!
delete_node(file_info);
get_file_info(pathname_request, "volatile.file_info");
file_info = "volatile.file_info";
string parent_directory = convert_name_to_integer_string(node_value(subnode_by_name(file_info, "parent")));
)
else (
show_path_not_found_alert = true;
invalid_pathname = pathname_request;
invalid_pathname = replace_all(invalid_pathname, "\\", "\\u005C");
invalid_pathname = replace_all(invalid_pathname, "'", "\'");
pathname_request = "";
);
)
else (
# if there is no pathname defined yet (first time load)
pathname_request = "";
);
=}
\n';
# ---------------------------------------------
# Build Net Use (connect to mapped drives) form
# ---------------------------------------------
if (_PLATFORM eq "Win32") then (
'
\n';
'
' . lang_admin.file_manager.map_drive_info . '
\n';
'
';
'
\n';
);
# ------------------
# Handle directories
# ------------------
get_directory_contents(pathname_request, "volatile.directory_contents");
node directory_contents = "volatile.directory_contents";
node item;
debug_message("\n\n@@@@ directory_contents:\n" . node_as_string(directory_contents) . "\n");
sort(directory_contents, "field:label,alphabetical,ascending", false);
bool is_directory;
string item_label;
string item_type;
string item_pathname;
int item_file_size;
string file_size_unit;
string file_size;
string link;
int id_number;
string directory_id;
string file_id;
'
\n';
'
\n';
'\n';
'\n';
'\n';
# ----------------------------------------------------------------
# Display "Root" or the path on which folders and files are zoomed
# ----------------------------------------------------------------
'\n';
if (pathname_request ne "") then (
# make sure that the parent directory always ends with a trailing slash
string divider = (if (_PLATFORM eq "UNIX") then "/" else "\\");
bool trailing_slash_exists = ends_with(pathname_request, divider);
if (!trailing_slash_exists) then (pathname_request .= divider);
string pathname_request_js = convert_name_to_integer_string(pathname_request);
string pathname_request_display = encode_display(pathname_request);
'\n';
debug_message("#### #### parent dir: " . parent_directory . "\n");
'`;
)
else (
'onclick="set_root_directory(this)">';
);
' \n';
`` . pathname_request_display . `\n`;
' | \n';
)
else (
'' . lang_admin.file_manager.root_label . ' | \n';
);
'
\n';
'
\n';
'
\n';
'\n';
'\n';
'\n';
'\n';
# ------
# drives
# ------
id_number = 0;
foreach item directory_contents (
item_type = node_value(subnode_by_name(item, "type"));
if (item_type eq "drive") then (
item_label = encode_display(node_value(subnode_by_name(item, "label")));
item_pathname = convert_name_to_integer_string(node_value(subnode_by_name(item, "pathname")));
id_number++;
directory_id = "dir" . id_number;
'\n';
'\n';
` \n`;
`[ ` . item_label . ` ]\n`;
' | \n';
' | \n';
'
\n';
);
);
# -----------
# directories
# -----------
# id_number = 0;
# continue with id number from drive!
foreach item directory_contents (
item_type = node_value(subnode_by_name(item, "type"));
if (item_type eq "directory") then (
item_label = encode_display(node_value(subnode_by_name(item, "label")));
item_pathname = convert_name_to_integer_string(node_value(subnode_by_name(item, "pathname")));
id_number++;
directory_id = "dir" . id_number;
'\n';
'\n';
` \n`;
`` . item_label . `\n`;
' | \n';
' | \n';
'
\n';
);
);
# -----------
# files
# -----------
id_number = 0;
foreach item directory_contents (
item_type = node_value(subnode_by_name(item, "type"));
if (item_type eq "file") then (
item_label = encode_display(node_value(subnode_by_name(item, "label")));
item_pathname = convert_name_to_integer_string(node_value(subnode_by_name(item, "pathname")));
if (subnode_exists(item, "file_size")) then (
item_file_size = node_value(subnode_by_name(item, "file_size"));
)
else (
item_file_size = 0;
);
# format file size
file_size_unit = "B";
if (item_file_size >= 1024) then (
file_size_unit = "K";
if (item_file_size >= (1024 * 1024)) then (
file_size_unit = "M";
);
);
# Bytes
if (file_size_unit eq "B") then (
file_size = item_file_size . " b";
);
# Kilobytes
if (file_size_unit eq "K") then (
item_file_size = item_file_size / 1024;
file_size = item_file_size . " K";
);
# Megabytes
if (file_size_unit eq "M") then (
item_file_size = item_file_size / (1024 * 1024);
file_size = item_file_size . " M";
);
id_number++;
file_id = "file" . id_number;
'\n';
'\n';
' \n';
`` . item_label . `\n`;
' | \n';
'' . file_size . ' | \n';
'
\n';
);
);
'
\n';
'
\n';
# '
\n';
=}