delete.tcl

delete items

Location:
/packages/file-storage/www/delete.tcl

Related Files

[ hide source ] | [ make this the default ]

File Contents

ad_page_contract {
    delete items
} {
    object_id:multiple,naturalnum,notnull
    {confirm_p:optional,boolean 0}
    {return_url:localurl ""}
}

set user_id [ad_conn user_id]

template::list::create \
    -name delete_list \
    -multirow delete_list \
    -key fs_object_id \
    -no_data "No items selected" \
    -elements {
        name {
            label "\#file-storage.Name\#"
        }
        delete_message {
            label ""
        }
    }

set allowed_count 0
set not_allowed_count 0

set root_folders_count [db_string count_root_folders "" -default 0]
if {$root_folders_count > 0} {
    ad_complain [_ file-storage.lt_You_may_not_delete_th]
    ad_script_abort
}

set F [db_list_of_lists . [subst {
    select fs.object_id as fs_object_id, fs.type, fs.name, fs.parent_id,
    acs_permission.permission_p(fs.object_id, :user_id, 'delete') as delete_p
    from fs_objects fs
    where fs.object_id in ([ns_dbquotelist $object_id])
}]]

db_multirow -extend {delete_message} delete_list get_to_be_deleted [subst {
    select fs.object_id as fs_object_id, fs.type, fs.name, fs.parent_id,
    acs_permission.permission_p(fs.object_id, :user_id, 'delete') as delete_p
    from fs_objects fs
    where fs.object_id in ([ns_dbquotelist $object_id])
}] {
    if {$delete_p} {
        set delete_message ""
        incr allowed_count
    } else {
        set delete_message [_ file-storage.Not_Allowed]
        incr not_allowed_count
    }
}

set total_count [template::multirow size delete_list]
set delete_inform [_ file-storage.lt_Do_you_want_to_delete]

ad_form -name delete_confirm -cancel_url $return_url -form {
    {notice:text(inform) {label ""} {value $delete_inform}}
    {return_url:text(hidden) {value $return_url}}
    {object_id:naturalnum(hidden) {values $object_id}}
}

ad_form -extend -name delete_confirm -on_submit {
    set object_id [split $object_id]
    db_transaction {
        template::multirow foreach delete_list {
            if {$delete_p} {
                switch -- $type {
                    folder {
                        fs::delete_folder \
                            -folder_id $fs_object_id \
                            -parent_id $parent_id
                    }
                    default {
                        fs::delete_file \
                            -item_id $fs_object_id \
                            -parent_id $parent_id
                    }
                }

            }
        }
    }
    ad_returnredirect $return_url
    ad_script_abort
}

set title "\#file-storage.Delete\#"
set context [list "\#file-storage.Delete\#"]


# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: