Index: openacs-4/packages/forums/lib/message/post.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/lib/message/post.tcl,v diff -u -r1.8 -r1.9 --- openacs-4/packages/forums/lib/message/post.tcl 14 Dec 2005 17:40:56 -0000 1.8 +++ openacs-4/packages/forums/lib/message/post.tcl 15 Jun 2006 06:42:35 -0000 1.9 @@ -19,162 +19,188 @@ set table_border_color [parameter::get -parameter table_border_color] set table_bgcolor [parameter::get -parameter table_bgcolor] + ############################## # Form definition # -form create message \ - -edit_buttons [list [list [_ forums.Post] post] \ + +set edit_buttons [list [list [_ forums.Post] post] \ [list [_ forums.Preview] preview]] -element create message message_id \ - -label [_ forums.Message_ID] \ - -datatype integer \ - -widget hidden +set form_elements { + {message_id:key} + {subject:text(text) + {html {size 60}} + {label "[_ forums.Subject]"} + } + {message_body:richtext(richtext) + {html {rows 20 cols 60 wrap soft}} + {label "[_ forums.Body]"} + } + {forum_id:integer(hidden) + } + {parent_id:integer(hidden),optional + } + {subscribe_p:text(hidden),optional + } + {confirm_p:text(hidden),optional + } +} -forums::form::message message +# Deal with anonymous postings +if {[expr {$user_id != 0 && $anonymous_allowed_p}]} { + append form_elements { + {anonymous_p:integer(checkbox),optional + {options {{"[_ forums.post_anonymously]" 1}}} + {label "[_ forums.Anonymous]"} + } + } +} else { + append form_elements { + {anonymous_p:integer(hidden),optional + } + } +} -forums::form::post_message \ - -show_anonymous_p [expr {$user_id != 0 && $anonymous_allowed_p}] \ - -show_attachments_p $attachments_enabled_p \ - message - -element create message confirm_p \ - -label [_ forums.Confirm] \ - -datatype text \ - -widget hidden - -if {[form is_request message]} { - ############################## - # Form initialisation - # - array set init_msg [list] - - set init_msg(message_id) [db_nextval acs_object_id_seq] - - if {[empty_string_p $parent_id]} { - forum::message::initial_message \ - -forum_id $forum_id \ - -message init_msg - } else { - forum::message::initial_message \ - -parent parent_message \ - -message init_msg +# Attachments +if {[expr {$user_id != 0 && $anonymous_allowed_p}]} { + append form_elements { + {attach_p:integer(radio),optional + {options {{[_ acs-kernel.common_No] 0} {[_ acs-kernel.common_Yes] 1}}} + {label "[_ forums.Attach]"} + } } +} else { + append form_elements { + {attach_p:integer(hidden),optional + } + } +} - set init_msg(confirm_p) 0 - set init_msg(subscribe_p) 0 - set init_msg(anonymous_p) 0 - set init_msg(attach_p) 0 +ad_form -html {enctype multipart/form-data} \ + -name message \ + -edit_buttons $edit_buttons \ + -form $form_elements \ + -new_request { + ############################## + # Form initialisation + # + set message_id [db_nextval acs_object_id_seq] + if {[empty_string_p $parent_id]} { + set parent_id "" + } else { + set forum_id $parent_message(forum_id) + set subject [forum::format::reply_subject $parent_message(subject)] + } + + set confirm_p 0 + set subscribe_p 0 + set anonymous_p 0 + set attach_p 0 + } -on_submit { - form set_values message init_msg - -} elseif {[form is_valid message]} { - - ############################## - # Form processing - # - form get_values message \ - message_id \ - forum_id \ - parent_id \ - subject \ - message_body \ - confirm_p \ - subscribe_p \ - anonymous_p \ - attach_p - - if { [empty_string_p $anonymous_p] } { set anonymous_p 0 } - - set action [template::form::get_button message] - set displayed_user_id [ad_decode \ - [expr {$anonymous_allowed_p && $anonymous_p}] \ - 0 $user_id \ - 0] - - if { [string equal $action "preview"] } { - - set confirm_p 1 - set subject.spellcheck ":nospell:" - set content.spellcheck ":nospell:" - set content [template::util::richtext::get_property content $message_body] - set format [template::util::richtext::get_property format $message_body] + ############################## + # Form processing + # - set exported_vars [export_vars -form {message_id forum_id parent_id subject {message_body $content} {message_body.format $format} confirm_p subject.spellcheck content.spellcheck anonymous_p attach_p}] - - set message(format) $format - set message(subject) $subject - set message(content) $content - set message(user_id) $displayed_user_id - set message(user_name) [db_string select_name {}] - set message(posting_date_ansi) [db_string select_date {}] - set message(posting_date_pretty) [lc_time_fmt $message(posting_date_ansi) "%x %X"] + if { [empty_string_p $anonymous_p] } { set anonymous_p 0 } + - # Let's check if this person is subscribed to the forum - # in case we might want to subscribe them to the thread - if {[empty_string_p $parent_id]} { - if {![empty_string_p [notification::request::get_request_id \ - -type_id [notification::type::get_type_id -short_name forums_forum_notif] \ - -object_id $forum_id \ - -user_id [ad_conn user_id]]]} { - set forum_notification_p 1 - } else { - set forum_notification_p 0 - } - } + set action [template::form::get_button message] - ad_return_template "/packages/forums/lib/message/post-confirm" - return - } + # Make post the default action + if {$action eq ""} { + set action preview + } - if { [string equal $action "post"] } { - set content [template::util::richtext::get_property content $message_body] - set format [template::util::richtext::get_property format $message_body] + set displayed_user_id [ad_decode \ + [expr {$anonymous_allowed_p && $anonymous_p}] \ + 0 $user_id \ + 0] - forum::message::new \ - -forum_id $forum_id \ - -message_id $message_id \ - -parent_id $parent_id \ - -subject $subject \ - -content $content \ - -format $format \ - -user_id $displayed_user_id + if { [string equal $action "preview"] } { + + set confirm_p 1 + set subject.spellcheck ":nospell:" + set content.spellcheck ":nospell:" + set content [template::util::richtext::get_property content $message_body] + set format [template::util::richtext::get_property format $message_body] + + set exported_vars [export_vars -form {message_id forum_id parent_id subject {message_body $content} {message_body.format $format} confirm_p subject.spellcheck content.spellcheck anonymous_p attach_p}] + + set message(format) $format + set message(subject) $subject + set message(content) $content + set message(user_id) $displayed_user_id + set message(user_name) [db_string select_name {}] + set message(posting_date_ansi) [db_string select_date {}] + set message(posting_date_pretty) [lc_time_fmt $message(posting_date_ansi) "%x %X"] + + # Let's check if this person is subscribed to the forum + # in case we might want to subscribe them to the thread + if {[empty_string_p $parent_id]} { + if {![empty_string_p [notification::request::get_request_id \ + -type_id [notification::type::get_type_id -short_name forums_forum_notif] \ + -object_id $forum_id \ + -user_id [ad_conn user_id]]]} { + set forum_notification_p 1 + } else { + set forum_notification_p 0 + } + } + + ad_return_template "/packages/forums/lib/message/post-confirm" + } - # DRB: Black magic cache flush call which will disappear when list builder is - # rewritten to paginate internally rather than use the template paginator. - cache flush "messages,forum_id=$forum_id*" - - if {[empty_string_p $parent_id]} { - set redirect_url "[ad_conn package_url]message-view?message_id=$message_id" - } else { - set redirect_url "[ad_conn package_url]message-view?message_id=$parent_id" - } - - # Wrap the notifications URL - if {![empty_string_p $subscribe_p] && $subscribe_p && [empty_string_p $parent_id]} { - set notification_url [notification::display::subscribe_url \ - -type forums_message_notif \ - -object_id $message_id \ - -url $redirect_url \ - -user_id $user_id] - - # redirect to notification stuff - set redirect_url $notification_url - } - - # Wrap the attachments URL - if {$attachments_enabled_p} { - if { ![empty_string_p $attach_p] && $attach_p} { - set redirect_url [attachments::add_attachment_url -object_id $message_id -return_url $redirect_url -pretty_name "[_ forums.Forum_Posting] \"$subject\""] - } - } - - # Do the redirection - ad_returnredirect $redirect_url - ad_script_abort + if { [string equal $action "post"] } { + set content [template::util::richtext::get_property content $message_body] + set format [template::util::richtext::get_property format $message_body] + + forum::message::new \ + -forum_id $forum_id \ + -message_id $message_id \ + -parent_id $parent_id \ + -subject $subject \ + -content $content \ + -format $format \ + -user_id $displayed_user_id + + # DRB: Black magic cache flush call which will disappear when list builder is + # rewritten to paginate internally rather than use the template paginator. + cache flush "messages,forum_id=$forum_id*" + + if {[empty_string_p $parent_id]} { + set redirect_url "[ad_conn package_url]message-view?message_id=$message_id" + } else { + set redirect_url "[ad_conn package_url]message-view?message_id=$parent_id" + } + + # Wrap the notifications URL + if {![empty_string_p $subscribe_p] && $subscribe_p && [empty_string_p $parent_id]} { + set notification_url [notification::display::subscribe_url \ + -type forums_message_notif \ + -object_id $message_id \ + -url $redirect_url \ + -user_id $user_id] + + # redirect to notification stuff + set redirect_url $notification_url + } + + # Wrap the attachments URL + if {$attachments_enabled_p} { + if { ![empty_string_p $attach_p] && $attach_p} { + set redirect_url [attachments::add_attachment_url -object_id $message_id -return_url $redirect_url -pretty_name "[_ forums.Forum_Posting] \"$subject\""] + } + } + + # Do the redirection + ad_returnredirect $redirect_url + ad_script_abort + } } -} + if {[exists_and_not_null alt_template]} { - ad_return_template $alt_template + ad_return_template $alt_template }