Index: openacs-4/packages/forums/www/message-post.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/www/message-post.tcl,v diff -u -r1.1.1.1 -r1.1.1.2 --- openacs-4/packages/forums/www/message-post.tcl 29 May 2002 21:40:10 -0000 1.1.1.1 +++ openacs-4/packages/forums/www/message-post.tcl 28 Jun 2006 20:30:29 -0000 1.1.1.2 @@ -1,70 +1,85 @@ - ad_page_contract { Form to create message and insert it - @author Ben Adida (ben@openforce) + @author Ben Adida (ben@openforce.net) @creation-date 2002-05-25 - @cvs-id $id: Exp $ -} { + @cvs-id $Id$ + +} -query { {forum_id ""} {parent_id ""} +} -validate { + forum_id_or_parent_id { + if {[empty_string_p $forum_id] && [empty_string_p $parent_id]} { + ad_complain [_ forums.lt_You_either_have_to] + } + } } -# Either forum_id or parent_id has to be non-null -if {[empty_string_p $forum_id] && [empty_string_p $parent_id]} { - # error! - return -code error +if { ![empty_string_p [ns_queryget formbutton:post]] } { + set action post +} elseif { ![empty_string_p [ns_queryget formbutton:preview]] } { + set action preview +} elseif { ![empty_string_p [ns_queryget formbutton:edit]] } { + set action edit +} else { + set action "" } -# We would use the nice ad_form construct if we could -form create message +set user_id [auth::refresh_login] -element create message message_id \ - -label "Message ID" -datatype integer -widget hidden +############################## +# Pull out required forum and parent data and +# perform security checks +# +if {[empty_string_p $parent_id]} { + # no parent_id, therefore new thread + # require thread creation privs + forum::security::require_post_forum -forum_id $forum_id -element create message subject \ - -label "Subject" -datatype text -widget text -html {size 60} + forum::get -forum_id $forum_id -array forum +} else { + # get the parent message information + forum::message::get -message_id $parent_id -array parent_message + set parent_message(tree_level) 0 -element create message content \ - -label "Body" -datatype text -widget textarea -html {rows 30 cols 60 wrap soft} + # see if they're allowed to add to this thread + forum::security::require_post_message -message_id $parent_id -element create message parent_id \ - -label "parent ID" -datatype integer -widget hidden -optional + forum::get -forum_id $parent_message(forum_id) -array forum +} -element create message forum_id \ - -label "forum ID" -datatype integer -widget hidden +############################## +# Calculate users rights and forums policy +# +set anonymous_allowed_p [expr ([empty_string_p $forum_id] || \ + [forum::security::can_post_forum_p \ + -forum_id $forum_id -user_id 0]) && \ + ([empty_string_p $parent_id] || \ + [forum::security::can_post_message_p \ + -message_id $parent_id -user_id 0])] -element create message html_p \ - -label "Format" -datatype text -widget select -options {{text f} {html t}} +set attachments_enabled_p [forum::attachments_enabled_p] -if {[form is_valid message]} { - template::form get_values message message_id forum_id parent_id subject content html_p +############################## +# Template variables +# - forum::message::new -forum_id $forum_id \ - -message_id $message_id \ - -parent_id $parent_id \ - -subject $subject \ - -content $content \ - -html_p $html_p +if {![string equal [template::form::get_button message] "preview"]} { + set context [list [list "./forum-view?forum_id=$forum_id" [ad_quotehtml $forum(name)]]] - ad_returnredirect "message-view?message_id=$message_id" - ad_script_abort -} + if {[empty_string_p $parent_id]} { + lappend context [_ forums.Post_a_Message] + } else { + lappend context [list "./message-view?message_id=$parent_message(message_id)" "$parent_message(subject)"] + lappend context [_ forums.Post_a_Reply] + } +} else { + set context [list [list "./forum-view?forum_id=$forum_id" [ad_quotehtml $forum(name)]]] + lappend context "[_ forums.Post_a_Message]" -set message_id [db_nextval acs_object_id_seq] - -if {[empty_string_p $forum_id]} { - # get the parent message information - forum::message::get -message_id $parent_id -array parent_message - set forum_id $parent_message(forum_id) + ad_return_template "message-post-confirm" } -forum::get -forum_id $forum_id -array forum -# Prepare the other data -element set_properties message forum_id -value $forum_id -element set_properties message parent_id -value $parent_id -element set_properties message message_id -value $message_id - -ad_return_template