fs_folder_def_selection db user_id { group_id " " } { public_p " " } { file_id " " } { folder_default " " }What it does:
Write out the SELECT box that allows the user to move a file to another folder, or - if folder_default is provided - create a new folder.Defined in: /web/philip/tcl/file-storage-defs.tcl
Source code:
# Get the current location of the file (ie parent_id).
if {![empty_string_p $file_id]} {
set current_parent_id [database_to_tcl_string $db "select parent_id from fs_files where file_id=$file_id"]
# We don't want to display any folders which are children
# of the selected file, so use this clause to block them.
set children_clause "and fs_files_tree.file_id not in (select file_id
from fs_files
connect by prior file_id = parent_id
start with file_id = $file_id)"
} else {
set current_parent_id ""
set children_clause ""
}
if { [info exists group_id] && ![empty_string_p $group_id] && $public_p != "t"} {
set sql_query "select file_title as folder, fs_files_tree.file_id as new_parent, lpad('x',the_level,'x') as spaces
from fs_files_tree
where folder_p='t'
and (public_p <> 't' or public_p is null)
and group_id = $group_id
and deleted_p = 'f' $children_clause"
set group_name [database_to_tcl_string $db "select group_name from user_groups where group_id=$group_id"]
set top_level "$group_name group tree"
} elseif {[info exists public_p] && $public_p == "t"} {
set sql_query "select file_title as folder, fs_files_tree.file_id as new_parent, lpad('x',the_level,'x') as spaces
from fs_files_tree
where folder_p='t'
and owner_id=$user_id
and public_p = 't'
and group_id is null
and deleted_p = 'f' $children_clause"
set top_level "Shared user tree"
} else {
set sql_query "select file_title as folder, fs_files_tree.file_id as new_parent, lpad('x',the_level,'x') as spaces
from fs_files_tree
where folder_p='t'
and owner_id=$user_id
and public_p = 'f'
and group_id is null
and deleted_p = 'f' $children_clause"
set top_level "Private user tree"
}
if {[empty_string_p $current_parent_id] && [empty_string_p $folder_default]} {
set file_options "<option value=\"\" selected> $top_level </option>\n"
} else {
set file_options "<option value=\"\" > $top_level </option>\n"
}
set folder_count 0
set selection [ns_db select $db $sql_query]
while {[ns_db getrow $db $selection]} {
set_variables_after_query
regsub -all x $spaces {\ \ } spaces
if {$file_id != $new_parent} {
incr folder_count
if { $current_parent_id == $new_parent || $folder_default == $new_parent } {
append file_options "<option value=$new_parent selected>$spaces $folder</option>\n"
} else {
append file_options "<option value=$new_parent >$spaces $folder</option>\n"
}
}
}
if { $folder_count > 8 } {
set size_count 8
} else {
set size_count [expr $folder_count +1]
}
set file_options_list "
<select size=$size_count name=parent_id>
$file_options
</select>
"
return $file_options_list