ad_page_contract {
    @author Richard Hamilton (richard.hamilton@webteamworks.com)
    @creation-date 18-09-2005
    @cvs-id@ $Id$
    Intrasite Message display page
} {
    {extra_stuff:optional ""}
    {objects_page:optional "1"}
    {objects_orderby:optional "sent_date"}
    {objects_context:optional "In-Box"}
}

# the unique identifier for this package
set package_id  [ad_conn package_id]
set package_url [ad_conn package_url]
set user_id     [ad_conn user_id]

# Check permissions on the package_id
ad_require_permission $package_id read

set title "Secure Messages"
set context [ list "Message List" ]

set extra_stuff "user_id"
lappend extra_stuff "$user_id"

set orderby "order by $objects_orderby"

set context_column "folder_name"
if {[empty_string_p $objects_context] } {
    set context_clause ""
   } else {
     set context_clause "and upper($context_column) like upper('$objects_context%')"
}

# Set identity column header to be 'From' unless in the sent messages folder.
if { $objects_context == "Sent-box" || $objects_context == "Drafts" } {
    set message_table_info {
        { priority_p "" {priority_p} "<td width=\"2%\" class=\"im_message_list_priority_p\">$priority_p</td>" }
        { selected "" {} "<td width=\"3%\"><input type=\"checkbox\" name=\"selected_messages\" value=\"$message_id\" id=\"entries,$message_id,\" title=\"Check/uncheck this row, and select and action below\"></td>" }
        { identity "To" {identity} "<td width=\"30%\" class=\"im_message_list\">$identity&nbsp;&nbsp;&nbsp;</td>" }
        { subject "Subject" {subject} "<td class=\"im_message_list\"><a href=\"./message-display?message_id=$message_id\">$subject</a>&nbsp;&nbsp;&nbsp;</td>" }
        { sent_date "Date" {sent_date} "<td width=\"17%\" class=\"im_message_list\">$sent_date</td>" }
    }
} else {
    set message_table_info {
        { priority_p "" {priority_p} "<td width=\"2%\" class=\"im_message_list_priority_p\">$priority_p</td>" }
        { selected "" {} "<td width=\"3%\"><input type=\"checkbox\" name=\"selected_messages\" value=\"$message_id\" id=\"entries,$message_id,\" title=\"Check/uncheck this row, and select and action below\"></td>" }
        { identity "From" {identity} "<td width=\"30%\" class=\"im_message_list\" nowrap=\"true\">$identity&nbsp;&nbsp;&nbsp;</td>" }
        { subject "Subject" {subject} "<td class=\"im_message_list\"><a href=\"./message-display?message_id=$message_id\">$subject</a>&nbsp;&nbsp;&nbsp;</td>" }
        { sent_date "Date" {sent_date} "<td width=\"17%\" class=\"im_message_list\">$sent_date</td>" }
    }
}

# Get count of unread or unsent messages for folder list


set sample_html [tools::paginate -name objects -page objects_page \
-queryname get_messages -context_field $context_column -array_name object_paginate_info \
-table_info $message_table_info -extra_vars [list extra_stuff]]

set folder_table_info {
    { folder_name "<span class=\"im_folder_list_heading\">Folder</span>" {folder_name} "<td width=100%  class=\"im_folder_list\">\n
      <a href=\"/messages/?objects%5fcontext=$folder_name\">$folder_name</a> "}
    { pending_messages "" {pending_messages} "$pending_messages" }
    { edit_link "" {} r }
}

set folder_panel [ad_table -Tband_colors { {} {} } -Theader_row_extra { align="left" bgcolor="#f8f8f8"} get_folders "" $folder_table_info]

db_multirow folders_for_select folders_for_select {
        select folder_id, folder_name
        from im_folder f
        where immutable_p = True
        or (immutable_p = False and user_id = :user_id)
}

ad_return_template


