Index: openacs-4/packages/simulation/lib/messages.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/messages.tcl,v diff -u -N -r1.12 -r1.13 --- openacs-4/packages/simulation/lib/messages.tcl 12 Jan 2004 13:43:14 -0000 1.12 +++ openacs-4/packages/simulation/lib/messages.tcl 12 Jan 2004 15:14:36 -0000 1.13 @@ -11,21 +11,25 @@ case_id { required_p 0 } + role_id { + required_p 0 + } limit { default_value {} } } -# TODO: finish. if case id is nil, check that adminplayer_p is true. if not, fail. -# if admin is true, ... - set package_id [ad_conn package_id] set adminplayer_p [permission::permission_p -object_id $package_id -privilege sim_adminplayer] -if { [exists_and_not_null case_id] } { - set user_roles [workflow::case::get_user_roles -case_id $case_id] +if { ![exists_and_not_null case_id] || ![exists_and_not_null role_id] } { + if { !$adminplayer_p } { + error "You must supply both case_id and role_id" + } else { + set mode "admin" + } } else { - set user_roles [list] + set mode "user" } set elements { @@ -34,11 +38,9 @@ } to { label "To" - hide_p {[ad_decode [llength $user_roles] 1 1 0]} } subject { - link_url_col - message_url + link_url_col message_url label "Subject" } creation_date { @@ -59,15 +61,21 @@ } } +if { [exists_and_not_null case_id] } { + set actions [list "Send new message" [export_vars -base message { case_id role_id }] {}] +} else { + set actions [list] +} + template::list::create \ -name messages \ -multirow messages \ -no_data "You don't have any messages." \ - -actions [list "Send new message" [export_vars -base message { case_id }] {}] \ + -actions $actions \ -elements $elements db_multirow -extend { message_url creation_date_pretty } messages select_messages " - select distinct sm.message_id, + select sm.message_id, cr.item_id, sm.title as subject, sc.label as case_label, @@ -82,27 +90,30 @@ where tr.role_id = sm.to_role_id) as to, (select count(*) from cr_item_rels - where item_id = item_id - and relation_tag = 'attachment') as attachment_count + where item_id = sm.item_id + and relation_tag = 'attachment') as attachment_count, + sm.to_role_id, + sm.case_id as msg_case_id from sim_messagesx sm, cr_revisions cr, - workflow_case_role_party_map wcrmp, - party_approved_member_map pamm, workflows w, workflow_cases wc, sim_cases sc where cr.revision_id = sm.message_id - and pamm.member_id = :user_id - and wcrmp.party_id = pamm.party_id - and wcrmp.case_id = sm.case_id - and wcrmp.role_id = sm.to_role_id and wc.case_id = sm.case_id + [ad_decode $mode "user" "and (sm.to_role_id = :role_id or sm.from_role_id = :role_id)" ""] + and wc.case_id = sm.case_id and sc.sim_case_id = wc.object_id and w.workflow_id = wc.workflow_id - [ad_decode [exists_and_not_null case_id] 1 "and sm.case_id = :case_id" ""] + [ad_decode $mode "user" "and wc.case_id = :case_id" "and exists (select 1 from workflow_case_role_user_map where case_id = wc.case_id and (sm.to_role_id = role_id or sm.from_role_id = role_id) and user_id = :user_id)"] order by sm.creation_date desc [ad_decode $limit "" "" "limit $limit"] " { - set message_url [export_vars -base "[apm_package_url_from_id $package_id]simplay/message" { item_id case_id }] + + if { [string equal $mode "admin"] } { + set message_url [export_vars -base "[apm_package_url_from_id $package_id]simplay/message" { item_id { case_id $msg_case_id } { role_id $to_role_id } }] + } else { + set message_url [export_vars -base "[apm_package_url_from_id $package_id]simplay/message" { item_id case_id role_id }] + } set creation_date_pretty [lc_time_fmt $creation_date_ansi "%x %X"] }