Index: openacs-4/contrib/packages/forums/forums.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/Attic/forums.info,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/forums.info 23 Jan 2007 13:24:02 -0000 1.1 @@ -0,0 +1,42 @@ + + + + + Forums + Forums + f + f + + + OpenACS + Online discussion forums. + 2006-05-10 + OpenACS + This online discussion board software is the successor of the original bboard package. The biggest improvement is a scalable datamodel. Forums supports threaded and flat view, moderation, a stand alone search function as well as integration with the OpenACS search package and integration with the notifications package for email alerts. It also supports reply via email. + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + Index: openacs-4/contrib/packages/forums/lib/forums-portlet-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/Attic/forums-portlet-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums-portlet-oracle.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,49 @@ + +oracle + + + +SELECT r.* FROM ( +SELECT + b.subject AS subject, + b.message_id AS thread_id, + a.message_id AS message_id +FROM + (SELECT message_id, tree_sortkey, posting_date + FROM forums_messages + WHERE forum_id IN + (SELECT forum_id FROM forums_forums WHERE package_id = + :package_id and enabled_p = 't') + ORDER BY posting_date DESC) a, + forums_messages b +WHERE + b.parent_id IS NULL + AND b.tree_sortkey = tree.ancestor_key(a.tree_sortkey, 1) + AND b.forum_id IN + (SELECT forum_id FROM forums_forums WHERE package_id = :package_id + and enabled_p = 't') +ORDER BY a.posting_date DESC +) r WHERE rownum <= $n + + + + + +SELECT r.* +FROM +(SELECT + subject, message_id +FROM + forums_messages_approved +WHERE + forum_id IN + (SELECT forum_id FROM forums_forums WHERE package_id = :package_id + and enabled_p = 't') + AND parent_id IS NULL +ORDER BY + posting_date DESC) r +WHERE rownum <= $n + + + + \ No newline at end of file Index: openacs-4/contrib/packages/forums/lib/forums-portlet-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/Attic/forums-portlet-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums-portlet-postgresql.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,39 @@ + +postgresql7.3 + + +SELECT + b.subject AS subject, + b.message_id AS thread_id, + a.message_id AS message_id +FROM + (SELECT message_id, tree_sortkey, posting_date + FROM forums_messages + WHERE forum_id IN + (SELECT forum_id FROM forums_forums WHERE package_id = :package_id + and enabled_p = 't') + ORDER BY posting_date DESC LIMIT $n) a, + forums_messages b +WHERE + b.parent_id IS NULL + AND b.tree_sortkey = tree_root_key(a.tree_sortkey) + AND b.forum_id IN + (SELECT forum_id FROM forums_forums WHERE package_id = :package_id + and enabled_p = 't'); + + + +SELECT + subject, message_id +FROM + forums_messages_approved +WHERE + forum_id IN + (SELECT forum_id FROM forums_forums WHERE package_id = :package_id + and enabled_p = 't') + AND parent_id IS NULL +ORDER BY + posting_date DESC +LIMIT $n + + \ No newline at end of file Index: openacs-4/contrib/packages/forums/lib/forums-portlet.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/Attic/forums-portlet.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums-portlet.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,36 @@ + + +

@title@

+ +

Hot topics

+

None

+

+ @hot_topics.name@
+

+
+ +

New topics

+

None

+

+ @new_topics.name@
+

+
+
+ +

@title@

+ +

Hot Topics

+

None

+

+ @hot_topics.name@
+

+
+ +

New Topics

+

None

+

+ @new_topics.name@
+

+
+
+
Index: openacs-4/contrib/packages/forums/lib/forums-portlet.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/Attic/forums-portlet.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums-portlet.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,78 @@ +ad_page_contract { +

Include for displaying the latest threads/posts in a forums instance. + Note this takes the following parameters - not declared with + ad_page_contract because it's an include: + +

+} + +# validate args +if { ![exists_and_not_null package_id] + && ![exists_and_not_null base_url] } { + error "package_id and/or base_url must be given" +} +if { [info exists n] } { + # need to do a type check, as this is interpolated into the PG query + # (PG LIMIT clause doesn't accept bind vars) + if { ![string is integer $n] || ![expr $n > 0] } { + error "n must be an integer greater than 0" + } +} else { + set n 2 +} +if { ![info exists cache] || [expr $cache < 0] } { + set cache 0 +} +if { ![exists_and_not_null package_id] } { + set package_id [site_node::get_element \ + -url $base_url -element object_id] +} +if { ![exists_and_not_null base_url] } { + set base_url [lindex [site_node::get_url_from_object_id \ + -object_id $package_id] 0] +} +if { ![info exists title] } { + set title [apm_instance_name_from_id $package_id] +} +if { ![info exists show_empty_p] } { + set show_empty_p 1 +} + + +# obtain data (use list rather than multirow, as its easier to cache) +# identification problems (need package_id + n as part of key) +set new_topics_script "# /packages/forums/lib/forums-portlet.tcl +set n $n +db_list_of_lists new_topics {} -bind { package_id $package_id }" +set hot_topics_script "# /packages/forums/lib/forums-portlet.tcl +set n $n +db_list_of_lists hot_topics {} -bind { package_id $package_id }" +set new_topics_ds [util_memoize $new_topics_script $cache] +set hot_topics_ds [util_memoize $hot_topics_script $cache] + +multirow create new_topics name url +foreach row $new_topics_ds { + set name [lindex $row 0] + set thread_id [lindex $row 1] + set url "${base_url}message-view?message_id=$thread_id" + multirow append new_topics $name $url +} + +multirow create hot_topics name url +foreach row $hot_topics_ds { + set name [lindex $row 0] + set thread_id [lindex $row 1] + set message_id [lindex $row 2] + set url "${base_url}message-view?message_id=${thread_id}\#${message_id}" + multirow append hot_topics $name $url +} + +ad_return_template Index: openacs-4/contrib/packages/forums/lib/forums/admin-forums-chunk.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/admin-forums-chunk.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/admin-forums-chunk.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1 @@ + Index: openacs-4/contrib/packages/forums/lib/forums/admin-forums-chunk.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/admin-forums-chunk.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/admin-forums-chunk.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,75 @@ +ad_page_contract { + + Forums Administration + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-24 + @cvs-id $Id: admin-forums-chunk.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} +set subsite_url [subsite::get_element -element url -notrailing] + +template::list::create \ + -name forums \ + -multirow forums \ + -actions [list \ + [_ forums.Create_a_New_Forum] forum-new {} \ + [_ forums.Parameters] [export_vars -base "$subsite_url/shared/parameters" { { return_url [ad_return_url] } { package_id {[ad_conn package_id]} } }] {} \ + [_ acs-subsite.Permissions] [export_vars -base "permissions" { { object_id {[ad_conn package_id]} } }] {} + ]\ + -elements { + edit { + label {} + sub_class narrow + display_template { + + } + link_url_col edit_url + } + name { + label "#forums.Forum_Name#" + link_url_col view_url + } + enabled { + label "Enabled" + html { align center } + display_template { + + \#forums.disable\# + + + \#forums.enable\# + + } + } + permissions { + label "#acs-subsite.Permissions#" + display_template "#acs-subsite.Permissions#" + link_url_col permissions_url + } + } + + +# List of forums +set package_id [ad_conn package_id] +db_multirow -extend { + view_url + edit_url + permissions_url + enable_url + disable_url +} forums select_forums {} { + if { [template::util::is_true $enabled_p] } { + set view_url [export_vars -base "[ad_conn package_url]forum-view" { forum_id }] + } else { + set view_url {} + } + set edit_url [export_vars -base "forum-edit" { forum_id }] + set permissions_url [export_vars -base permissions { { object_id $forum_id } }] + set enable_url [export_vars -base "forum-enable" { forum_id }] + set disable_url [export_vars -base "forum-disable" { forum_id }] +} + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} Index: openacs-4/contrib/packages/forums/lib/forums/admin-forums-chunk.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/admin-forums-chunk.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/admin-forums-chunk.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,13 @@ + + + + + +select forum_id, name, posting_policy, enabled_p +from forums_forums +where package_id= :package_id +order by enabled_p desc, name + + + + Index: openacs-4/contrib/packages/forums/lib/forums/edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/edit.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/edit.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1 @@ + Index: openacs-4/contrib/packages/forums/lib/forums/edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/edit.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/edit.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,57 @@ +ad_page_contract { + + Edit a Forum + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-25 + @cvs-id $Id: edit.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} { +} + +form create forum + +element create forum return_url \ + -datatype text -widget hidden -optional + +element create forum forum_id \ + -label [_ forums.Forum_ID] -datatype integer -widget hidden + +forums::form::forum forum + +if {[form is_valid forum]} { + template::form get_values forum return_url forum_id name charter presentation_type posting_policy new_threads_p + + forum::edit -forum_id $forum_id \ + -name $name \ + -charter [template::util::richtext::get_property contents $charter] \ + -presentation_type $presentation_type \ + -posting_policy $posting_policy + + forum::posting_policy_set -posting_policy $posting_policy \ + -forum_id $forum_id + + # Users can create new threads? + if {$new_threads_p} { + forum::new_questions_allow -forum_id $forum_id + } else { + forum::new_questions_deny -forum_id $forum_id + } + + ad_returnredirect $return_url + ad_script_abort +} + +if { [form is_request forum] } { + element set_properties forum return_url -value $return_url + element set_properties forum forum_id -value $forum(forum_id) + element set_properties forum name -value $forum(name) + element set_properties forum charter -value [template::util::richtext create $forum(charter) "text/html"] + element set_properties forum presentation_type -value $forum(presentation_type) + element set_properties forum posting_policy -value $forum(posting_policy) + element set_properties forum new_threads_p -value [forum::new_questions_allowed_p -forum_id $forum(forum_id)] +} + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} Index: openacs-4/contrib/packages/forums/lib/forums/forums-chunk-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/forums-chunk-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/forums-chunk-oracle.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,23 @@ + + + + oracle8.1.6 + + + + select forums_forums_enabled.*, + approved_thread_count as n_threads, + to_char(last_post, 'YYYY-MM-DD HH24:MI:SS') as last_post_ansi, + case when last_post > (sysdate - 1) then 't' else 'f' end as new_p + from forums_forums_enabled + where forums_forums_enabled.package_id = :package_id + and ( + forums_forums_enabled.posting_policy = 'open' + or forums_forums_enabled.posting_policy = 'moderated' + or 't' = acs_permission.permission_p(forums_forums_enabled.forum_id, :user_id, 'forum_read') + ) + order by forums_forums_enabled.name + + + + Index: openacs-4/contrib/packages/forums/lib/forums/forums-chunk-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/forums-chunk-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/forums-chunk-postgresql.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,31 @@ + + + + postgresql7.1 + + + + select f.*, + approved_thread_count as n_threads, + to_char(last_post, 'YYYY-MM-DD HH24:MI:SS') as last_post_ansi, + case when last_post > (now() - interval '1 day') then 't' else 'f' end as new_p, + (select count(*) + from forums_messages + where forums_messages.forum_id = f.forum_id) as total_message_count, + (select count(*) + from forums_messages + where forums_messages.forum_id = f.forum_id + and posting_date > (now() - interval '1 day')) as new_message_count + from $table_name f + where f.package_id = :package_id + and ( + f.posting_policy = 'open' + or f.posting_policy = 'moderated' + or 't' = acs_permission__permission_p(f.forum_id, :user_id,'forum_read') + ) + order by f.name + + + + + Index: openacs-4/contrib/packages/forums/lib/forums/forums-chunk.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/forums-chunk.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/forums-chunk.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1 @@ + Index: openacs-4/contrib/packages/forums/lib/forums/forums-chunk.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/forums-chunk.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/forums-chunk.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,120 @@ +ad_page_contract { + + top level list of forums + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-24 + @cvs-id $Id: forums-chunk.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} + +if { ! [exists_and_not_null package_id] } { + set package_id [ad_conn package_id] +} +set package_url [site_node::get_url_from_object_id -object_id $package_id] +set user_id [ad_conn user_id] + +set admin_p [permission::permission_p -object_id $package_id -privilege admin] + +# get the colors from the params +set table_border_color [parameter::get -parameter table_border_color] +set table_bgcolor [parameter::get -parameter table_bgcolor] +set table_other_bgcolor [parameter::get -parameter table_other_bgcolor] + +set actions [list] +if { $admin_p && ![info exists hide_admin_buttons_p]} { + lappend actions [_ forums.New_Forum] "admin/forum-new" {} + lappend actions [_ forums.Administration] "admin/" {} +} + +template::list::create \ + -name forums \ + -actions $actions \ + -no_data [_ forums.No_Forums] \ + -pass_properties {admin_p} \ + -sub_class {forums} \ + -elements { + name { + label {\#forums.Forum_Name\#} + display_template { + + + @forums.name@ + + +
+ @forums.charter;noquote@ + } + } + subscribe { + label {[_ forums.Subscription]} + display_template { + + UNSUBSCRIBE + SUBSCRIBE + + } + html { align center } + } + n_threads { + label {\#forums.Threads\#} + display_col n_threads_pretty + sub_class forums-thread + html { align right } + } + last_post { + label {\#forums.Last_Post\#} + display_col last_modified_pretty + } + message_counts { + label "MESSAGES" + display_template { + @forums.new_message_count@ NEW
+ \[@forums.total_message_count@ Total\] + } + } + actions { + display_template { + + EDIT
+ @forums.forum_disable_text@ +
+ } + } + } + +if {$admin_p} { + set table_name forums_forums +} { + set table_name forums_forums_enabled +} + +db_multirow -extend { forum_view_url last_modified_pretty n_threads_pretty forum_disable_url forum_edit_url forum_disable_text subscribed_p notif_url } forums select_forums {} { + set last_modified_pretty [lc_time_fmt $last_post_ansi "%x %X"] + set forum_view_url [export_vars -base ${package_url}forum-view { forum_id }] + set n_threads_pretty [lc_numeric $n_threads] + set return_url [ad_return_url] + if {$enabled_p == "t"} { + set forum_disable_url [export_vars -base "${package_url}admin/forum-disable" { forum_id return_url }] + set forum_disable_text DISABLE + } else { + set forum_disable_url [export_vars -base "${package_url}admin/forum-enable" { forum_id return_url }] + set forum_disable_text ENABLE + } + set forum_edit_url [export_vars -base "${package_url}admin/forum-edit" { forum_id return_url }] + + set type_id [notification::type::get_type_id -short_name forums_forum_notif] + set request_id [notification::request::get_request_id -type_id $type_id -object_id $forum_id -user_id $user_id] + + if { $request_id eq "" } { + set subscribed_p 0 + set notif_url [notification::display::subscribe_url -type forums_forum_notif -object_id $forum_id -url $return_url -user_id $user_id -pretty_name $name] + } else { + set subscribed_p 1 + set notif_url [notification::display::unsubscribe_url -request_id $request_id -url $return_url] + } +} + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} Index: openacs-4/contrib/packages/forums/lib/forums/forums-history-chunk.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/forums-history-chunk.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/forums-history-chunk.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,42 @@ +

+ #forums.Users_that_wrote_in_the_forum# @name@ +

+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#forums.User##forums.Number_of_Posts##forums.Posted#
@persons.first_names@ @persons.last_name@@persons.num_msg@@persons.last_post@
+ #forums.No_Postings# +
+ +
Index: openacs-4/contrib/packages/forums/lib/forums/forums-history-chunk.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/forums-history-chunk.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/forums-history-chunk.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,22 @@ +ad_page_contract { + + Forums History + + @author Natalia P�rez (nperper@it.uc3m.es) + @creation-date 2005-03-17 + +} + +set package_id [ad_conn package_id] + +# get the colors from the params +set table_border_color [parameter::get -parameter table_border_color] +set table_bgcolor [parameter::get -parameter table_bgcolor] +set table_other_bgcolor [parameter::get -parameter table_other_bgcolor] + + +db_multirow persons select_users_wrote_post {} + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} Index: openacs-4/contrib/packages/forums/lib/forums/forums-history-chunk.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/forums-history-chunk.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/forums-history-chunk.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,12 @@ + + + + + + select distinct forums_messages.user_id, persons.first_names, persons.last_name, count(user_id) as num_msg, to_char(max(last_child_post), 'YYYY-MM-DD HH24:MI:SS') as last_post + from persons, forums_messages + where forums_messages.user_id = persons.person_id and forums_messages.forum_id = :forum_id + group by forums_messages.user_id, persons.first_names, persons.last_name + + + Index: openacs-4/contrib/packages/forums/lib/forums/new.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/new.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/new.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1 @@ + Index: openacs-4/contrib/packages/forums/lib/forums/new.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/forums/Attic/new.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/forums/new.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,63 @@ +ad_page_contract { + + Create a Forum + By default redirects to the level above as that is prolly where the index page is + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-25 + @cvs-id $Id: new.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} + +if { ![info exists name] } { + set name {} +} + +set package_id [ad_conn package_id] + +form create forum + +element create forum forum_id \ + -label [_ forums.Forum_ID] \ + -datatype integer \ + -widget hidden + +forums::form::forum forum + +if {[form is_valid forum]} { + template::form get_values forum \ + forum_id name charter presentation_type posting_policy new_threads_p + + set forum_id [forum::new -forum_id $forum_id \ + -name $name \ + -charter [template::util::richtext::get_property contents $charter] \ + -presentation_type $presentation_type \ + -posting_policy $posting_policy \ + -package_id $package_id \ + ] + + forum::posting_policy_set -posting_policy $posting_policy \ + -forum_id $forum_id + + # Users can create new threads? + if {$new_threads_p} { + forum::new_questions_allow -forum_id $forum_id + } else { + forum::new_questions_deny -forum_id $forum_id + } + + ad_returnredirect $return_url + ad_script_abort +} + +if { [form is_request forum] } { + # Pre-fetch the forum_id + set forum_id [db_nextval acs_object_id_seq] + element set_properties forum forum_id -value $forum_id + element set_value forum new_threads_p 1 + element set_value forum name $name +} + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} Index: openacs-4/contrib/packages/forums/lib/message/attachment-list.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/attachment-list.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/attachment-list.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,7 @@ + Index: openacs-4/contrib/packages/forums/lib/message/attachment-list.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/attachment-list.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/attachment-list.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,24 @@ +ad_page_contract { + a message attachment chunk to be included to display attachments + + @author ben (ben@openforce.net) + @creation-date 2002-07-02 + @cvs-id $Id: attachment-list.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ +} + +if {![array exists message]} { + ad_return_complaint 1 "[_ forums.lt_need_to_provide_a_mes]" +} + +if {![exists_and_not_null bgcolor]} { + set bgcolor "#ffffff" +} + +# get the attachments +set attachments [attachments::get_attachments -object_id $message(message_id)] + +set attachment_graphic [attachments::graphic_url] + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} Index: openacs-4/contrib/packages/forums/lib/message/choose-forum-move.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose-forum-move.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose-forum-move.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,17 @@ +@title;noquote@ +@context;noquote@ + +

#forums.Move_thread_to_forum#

+ +
+ + + +

#forums.Sorry_you_can_not_move_this_thread_There_are_no_other_forums# + + + +

+ + + \ No newline at end of file Index: openacs-4/contrib/packages/forums/lib/message/choose-forum-move.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose-forum-move.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose-forum-move.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,49 @@ +# packages/forums/admin/moderate/choose_forum_move.tcl + +ad_page_contract { + + Show a list of available forums so that user can choose one. + + @author Natalia Perez (nperper@it.uc3m.es) + @creation-date 2005-03-15 +} { + {return_url "../message-view"} +} -properties { + context:onevalue +} -validate { +} -errors { +} + + + template::list::create \ + -name available_forums \ + -multirow forums \ + -key forum_id \ + -elements { + selected { + label #forums.Selected# + display_template { + + } + } + forum_id { + hide_p 1 + } + forum_name { + label #forums.Forum_Name# + display_col name + } + } + +db_0or1row get_package_id "select distinct(package_id) from forums_forums where forum_id = $message(forum_id)" +db_multirow forums get_forums " + select forum_id, name from forums_forums where forum_id <> $message(forum_id) and package_id = :package_id and enabled_p = 't' +" + +set message_id $message(message_id) + +# set context & title +set context [list "[_ forums.Available_Forums]"] +set title "[_ forums.Available_Forums]" + + Index: openacs-4/contrib/packages/forums/lib/message/choose-message-move-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose-message-move-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose-message-move-oracle.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,26 @@ + + + + oracle8.1.6 + + + + select substr(tree_sortkey, 0, 6) as father_tree_sortkey + from forums_messages + where message_id=$message(message_id) + + + + + + + + select parent_id + from forums_messages + where forum_id = $message(forum_id) and tree_sortkey between tree.left('$father_tree_sortkey') and tree.right('$father_tree_sortkey') + order by tree_sortkey desc + + + + + Index: openacs-4/contrib/packages/forums/lib/message/choose-message-move-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose-message-move-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose-message-move-postgresql.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,26 @@ + + + + postgresql7.1 + + + + select substring(tree_sortkey, 0, 9) as father_tree_sortkey + from forums_messages + where message_id=$message(message_id) + + + + + + + + select parent_id + from forums_messages + where forum_id = $message(forum_id) and tree_sortkey between tree_left('$father_tree_sortkey') and tree_right('$father_tree_sortkey') + order by tree_sortkey desc + + + + + Index: openacs-4/contrib/packages/forums/lib/message/choose-message-move.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose-message-move.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose-message-move.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,17 @@ +@title;noquote@ +@context;noquote@ + +

#forums.Move_message_to_message#

+ +
+ + + +

#forums.Sorry_you_can_not_move_this_message_There_are_no_other_threads#

+
+ + +

+ +
+
\ No newline at end of file Index: openacs-4/contrib/packages/forums/lib/message/choose-message-move.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose-message-move.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose-message-move.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,51 @@ +# packages/forums/admin/moderate/choose_message_move.tcl + +ad_page_contract { + + Show a list of available messages so that user can choose one. + + @author Natalia Perez (nperper@it.uc3m.es) + @creation-date 2005-03-17 +} { + {return_url "../message-view"} +} -properties { + context:onevalue +} -validate { +} -errors { +} + + template::list::create \ + -name available_messages \ + -multirow messages \ + -key message_id \ + -elements { + selected { + label #forums.Selected# + display_template { + + } + } + message_id { + hide_p 1 + } + message_subject { + label #forums.Message_Subject# + display_col subject + } + } + +db_0or1row get_tree_sortkey { } + +db_foreach get_parent_id { } { + db_multirow messages get_messages " + select message_id, subject from forums_messages where forum_id = $message(forum_id) and message_id <> $message(message_id) and parent_id is null and message_id <> :parent_id + " +} + +set msg_id $message(message_id) + +# set context & title +set context [list "[_ forums.Available_Messages]"] +set title "[_ forums.Available_Messages]" + + Index: openacs-4/contrib/packages/forums/lib/message/choose-thread-move.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose-thread-move.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose-thread-move.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,17 @@ +@title;noquote@ +@context;noquote@ + +

#forums.Move_thread_to_thread#

+ +
+ + + + #forums.Sorry_you_can_not_move_this_thread_There_are_no_more_threads# + + + +

+ +
+
\ No newline at end of file Index: openacs-4/contrib/packages/forums/lib/message/choose-thread-move.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose-thread-move.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose-thread-move.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,58 @@ +# packages/forums/admin/moderate/choose_message_move.tcl + +ad_page_contract { + + Show a list of available messages so that user can choose one. + + @author Natalia Perez (nperper@it.uc3m.es) + @creation-date 2005-03-17 +} { + {return_url "../message-view"} +} -properties { + context:onevalue +} -validate { +} -errors { +} + + template::list::create \ + -name available_messages \ + -multirow messages \ + -key message_id \ + -elements { + selected { + label #forums.Selected# + display_template { + + } + } + message_id { + hide_p 1 + } + forum_id { + label #forums.Name_of_forum# + display_col name + } + message_subject { + label #forums.Message_Subject# + display_col subject + } + } + + +db_0or1row get_package_id "select distinct(package_id) from forums_forums where forum_id = $message(forum_id)" +db_multirow messages get_messages " + select fm.forum_id, fm.message_id, fm.subject, ff.name + from forums_messages fm, forums_forums ff + where ff.package_id = :package_id and ff.enabled_p='t' and fm.message_id <> $message(message_id) and fm.parent_id is null + and fm.forum_id = ff.forum_id + order by fm.forum_id +" + + +set msg_id $message(message_id) + +# set context & title +set context [list "[_ forums.Available_Messages]"] +set title "[_ forums.Available_Messages]" + + Index: openacs-4/contrib/packages/forums/lib/message/choose_forum_move.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose_forum_move.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose_forum_move.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,17 @@ +@title;noquote@ +@context;noquote@ + +

#forums.Move_thread_to_forum#

+ +
+ + + +

#forums.Sorry_you_can_not_move_this_thread_There_are_no_other_forums# + + + +

+ + + \ No newline at end of file Index: openacs-4/contrib/packages/forums/lib/message/choose_forum_move.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose_forum_move.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose_forum_move.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,49 @@ +# packages/forums/admin/moderate/choose_forum_move.tcl + +ad_page_contract { + + Show a list of available forums so that user can choose one. + + @author Natalia Perez (nperper@it.uc3m.es) + @creation-date 2005-03-15 +} { + {return_url "../message-view"} +} -properties { + context:onevalue +} -validate { +} -errors { +} + + + template::list::create \ + -name available_forums \ + -multirow forums \ + -key forum_id \ + -elements { + selected { + label #forums.Selected# + display_template { + + } + } + forum_id { + hide_p 1 + } + forum_name { + label #forums.Forum_Name# + display_col name + } + } + +db_0or1row get_package_id "select distinct(package_id) from forums_forums where forum_id = $message(forum_id)" +db_multirow forums get_forums " + select forum_id, name from forums_forums where forum_id <> $message(forum_id) and package_id = :package_id and enabled_p = 't' +" + +set message_id $message(message_id) + +# set context & title +set context [list "[_ forums.Available_Forums]"] +set title "[_ forums.Available_Forums]" + + Index: openacs-4/contrib/packages/forums/lib/message/choose_message_move-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose_message_move-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose_message_move-oracle.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,26 @@ + + + + oracle8.1.6 + + + + select substr(tree_sortkey, 0, 6) as father_tree_sortkey + from forums_messages + where message_id=$message(message_id) + + + + + + + + select parent_id + from forums_messages + where forum_id = $message(forum_id) and tree_sortkey between tree.left('$father_tree_sortkey') and tree.right('$father_tree_sortkey') + order by tree_sortkey desc + + + + + Index: openacs-4/contrib/packages/forums/lib/message/choose_message_move-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose_message_move-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose_message_move-postgresql.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,26 @@ + + + + postgresql7.1 + + + + select substring(tree_sortkey, 0, 9) as father_tree_sortkey + from forums_messages + where message_id=$message(message_id) + + + + + + + + select parent_id + from forums_messages + where forum_id = $message(forum_id) and tree_sortkey between tree_left('$father_tree_sortkey') and tree_right('$father_tree_sortkey') + order by tree_sortkey desc + + + + + Index: openacs-4/contrib/packages/forums/lib/message/choose_message_move.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose_message_move.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose_message_move.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,17 @@ +@title;noquote@ +@context;noquote@ + +

#forums.Move_message_to_message#

+ +
+ + + +

#forums.Sorry_you_can_not_move_this_message_There_are_no_other_threads#

+
+ + +

+ +
+
\ No newline at end of file Index: openacs-4/contrib/packages/forums/lib/message/choose_message_move.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose_message_move.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose_message_move.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,51 @@ +# packages/forums/admin/moderate/choose_message_move.tcl + +ad_page_contract { + + Show a list of available messages so that user can choose one. + + @author Natalia Perez (nperper@it.uc3m.es) + @creation-date 2005-03-17 +} { + {return_url "../message-view"} +} -properties { + context:onevalue +} -validate { +} -errors { +} + + template::list::create \ + -name available_messages \ + -multirow messages \ + -key message_id \ + -elements { + selected { + label #forums.Selected# + display_template { + + } + } + message_id { + hide_p 1 + } + message_subject { + label #forums.Message_Subject# + display_col subject + } + } + +db_0or1row get_tree_sortkey { } + +db_foreach get_parent_id { } { + db_multirow messages get_messages " + select message_id, subject from forums_messages where forum_id = $message(forum_id) and message_id <> $message(message_id) and parent_id is null and message_id <> :parent_id + " +} + +set msg_id $message(message_id) + +# set context & title +set context [list "[_ forums.Available_Messages]"] +set title "[_ forums.Available_Messages]" + + Index: openacs-4/contrib/packages/forums/lib/message/choose_thread_move.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose_thread_move.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose_thread_move.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,17 @@ +@title;noquote@ +@context;noquote@ + +

#forums.Move_thread_to_thread#

+ +
+ + + + #forums.Sorry_you_can_not_move_this_thread_There_are_no_more_threads# + + + +

+ +
+
\ No newline at end of file Index: openacs-4/contrib/packages/forums/lib/message/choose_thread_move.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/choose_thread_move.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/choose_thread_move.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,58 @@ +# packages/forums/admin/moderate/choose_message_move.tcl + +ad_page_contract { + + Show a list of available messages so that user can choose one. + + @author Natalia Perez (nperper@it.uc3m.es) + @creation-date 2005-03-17 +} { + {return_url "../message-view"} +} -properties { + context:onevalue +} -validate { +} -errors { +} + + template::list::create \ + -name available_messages \ + -multirow messages \ + -key message_id \ + -elements { + selected { + label #forums.Selected# + display_template { + + } + } + message_id { + hide_p 1 + } + forum_id { + label #forums.Name_of_forum# + display_col name + } + message_subject { + label #forums.Message_Subject# + display_col subject + } + } + + +db_0or1row get_package_id "select distinct(package_id) from forums_forums where forum_id = $message(forum_id)" +db_multirow messages get_messages " + select fm.forum_id, fm.message_id, fm.subject, ff.name + from forums_messages fm, forums_forums ff + where ff.package_id = :package_id and ff.enabled_p='t' and fm.message_id <> $message(message_id) and fm.parent_id is null + and fm.forum_id = ff.forum_id + order by fm.forum_id +" + + +set msg_id $message(message_id) + +# set context & title +set context [list "[_ forums.Available_Messages]"] +set title "[_ forums.Available_Messages]" + + Index: openacs-4/contrib/packages/forums/lib/message/delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/delete.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/delete.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,12 @@ +

#forums.Are_you_sure_you_want_to_delete_lt#

+ +
+ +
+ + Index: openacs-4/contrib/packages/forums/lib/message/delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/delete.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/delete.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,31 @@ +ad_page_contract { + + Delete a Message + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-24 + @cvs-id $Id: delete.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} + +set table_border_color [parameter::get -parameter table_border_color] + +# Confirmed? +if {$confirm_p} { + # Delete the message and all children + forum::message::delete -message_id $message(message_id) + + # Redirect to the forum + ad_returnredirect "../forum-view?forum_id=$message(forum_id)" + ad_script_abort +} + +set message_id $message(message_id) + +set message(tree_level) 0 + +set url_vars [export_url_vars message_id return_url] + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} Index: openacs-4/contrib/packages/forums/lib/message/edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/edit.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/edit.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1 @@ + Index: openacs-4/contrib/packages/forums/lib/message/edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/edit.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/edit.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,44 @@ +ad_page_contract { + + Form to edit a message + + @author Ben Adida (ben@openforce.net) + @creation-date 2003-12-09 + @cvs-id $Id: edit.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} + +form create message + +element create message message_id \ + -label [_ forums.Message_ID] \ + -datatype integer \ + -widget hidden + +forums::form::message message + +if {[form is_valid message]} { + template::form get_values message message_id subject message_body + set content [string trimright [template::util::richtext::get_property contents $message_body]] + set format [string trimright [template::util::richtext::get_property format $message_body]] + + forum::message::edit \ + -message_id $message_id \ + -subject $subject \ + -content $content \ + -format $format + + ad_returnredirect "$return_url?message_id=$message_id" + ad_script_abort +} + +if { ! [template::form::is_submission message] } { + # Prepare the other data + element set_properties message message_id -value $message(message_id) + element set_properties message subject -value $message(subject) + element set_properties message message_body -value [list $message(content) $message(format)] +} + +if {[info exists alt_template]} { + ad_return_template $alt_template +} Index: openacs-4/contrib/packages/forums/lib/message/messages-list.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/messages-list.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/messages-list.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,9 @@ +

Recent messages

+ + + + +none + Index: openacs-4/contrib/packages/forums/lib/message/messages-list.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/messages-list.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/messages-list.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,12 @@ +set package_id [site_node::get_element -url $url -element package_id] + +db_multirow -extend {link} messages messages { + select m.subject, count(*) as n, max(m.message_id) as message_id,to_date(max(m.posting_date), 'YYYY-MM-DD HH24:MI:SS') as posted + from forums_forums f, forums_messages m + where f.package_id = :package_id + and m.forum_id = f.forum_id + and posting_date > now() - '5 days'::interval group by subject order by max(m.posting_date) desc +} { + set posted [lc_time_fmt $posted "%x %X"] + set link "message-view?message_id=$message_id" +} Index: openacs-4/contrib/packages/forums/lib/message/messages-table.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/messages-table.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/messages-table.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#forums.Subject##forums.Author##forums.Posting_Date#
+ @messages.subject@ + @messages.user_name@@messages.posting_date@
+ #forums.No_Messages# +
Index: openacs-4/contrib/packages/forums/lib/message/messages-table.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/messages-table.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/messages-table.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,18 @@ +ad_page_contract { + + Search messages for a string + + @author Rob Denison (rob@thaum.net) + @creation-date 2003-12-08 + @cvs-id $Id: messages-table.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} + +# get the colors from the params +set table_border_color [parameter::get -parameter table_border_color] +set table_bgcolor [parameter::get -parameter table_bgcolor] +set table_other_bgcolor [parameter::get -parameter table_other_bgcolor] + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} Index: openacs-4/contrib/packages/forums/lib/message/pending-list-chunk-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/pending-list-chunk-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/pending-list-chunk-oracle.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,20 @@ + + + + oracle8.1.6 + + + + select message_id, + subject + from forums_messages + where forum_id = :forum_id + and tree_sortkey in (select substr(tree_sortkey, 1, 6) + from forums_messages_pending + where forum_id = :forum_id) + order by tree_sortkey + + + + + Index: openacs-4/contrib/packages/forums/lib/message/pending-list-chunk-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/pending-list-chunk-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/pending-list-chunk-postgresql.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,20 @@ + + + + postgresql7.1 + + + + select message_id, + subject + from forums_messages + where forum_id = :forum_id + and tree_sortkey in (select tree_ancestor_key(tree_sortkey, 1) + from forums_messages_pending + where forum_id = :forum_id) + order by tree_sortkey + + + + + Index: openacs-4/contrib/packages/forums/lib/message/pending-list-chunk.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/pending-list-chunk.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/pending-list-chunk.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,10 @@ + Index: openacs-4/contrib/packages/forums/lib/message/pending-list-chunk.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/pending-list-chunk.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/pending-list-chunk.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,16 @@ +ad_page_contract { + + Moderate a Forum + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-24 + @cvs-id $Id: pending-list-chunk.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} + +# Get the threads that need approval +db_multirow pending_threads select_pending_threads {} + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} Index: openacs-4/contrib/packages/forums/lib/message/post-confirm.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/post-confirm.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/post-confirm.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,19 @@ +

#forums.lt_Please_confirm_the_fo#

+
+ +
+
+ + @exported_vars;noquote@ + + #forums.lt_Would_you_like_to_sub# + #forums.No# + #forums.Yes# + + +
#forums.lt_Note_that_you_are_alr# +
+
+ + +
Index: openacs-4/contrib/packages/forums/lib/message/post-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/post-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/post-oracle.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,12 @@ + + + oracle8.1.6 + + + + select to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') + from dual + + + + Index: openacs-4/contrib/packages/forums/lib/message/post-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/post-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/post-postgresql.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,12 @@ + + + + postgresql7.1 + + + + select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS') + + + + Index: openacs-4/contrib/packages/forums/lib/message/post.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/post.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/post.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,7 @@ + +
+ +
+
+ + Index: openacs-4/contrib/packages/forums/lib/message/post.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/post.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/post.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,179 @@ +ad_page_contract { + + Form to create message and insert it + + @author Ben Adida (ben@openforce.net) + @creation-date 2003-12-09 + @cvs-id $Id: post.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} + +set user_id [ad_conn user_id] + +if {[array exists parent_message]} { + set parent_id $parent_message(message_id) +} else { + set parent_id "" +} + +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] \ + [list [_ forums.Preview] preview]] + +element create message message_id \ + -label [_ forums.Message_ID] \ + -datatype integer \ + -widget hidden + +forums::form::message message + +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 + } + + set init_msg(confirm_p) 0 + set init_msg(subscribe_p) 0 + set init_msg(anonymous_p) 0 + set init_msg(attach_p) 0 + + 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] + + 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" + return + } + + 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 +} Index: openacs-4/contrib/packages/forums/lib/message/post.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/post.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/post.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,21 @@ + + + + + + + select first_names || ' ' || last_name + from persons + where person_id = :user_id + + + + + + select forum_id + from forums_messages + where message_id = :parent_id + + + + Index: openacs-4/contrib/packages/forums/lib/message/row.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/row.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/row.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,85 @@ +
+ + + + + + +
+
+ +

+ +
+
#forums.Posted_by# @message.user_name@
on
+
+ + +
+ +
+
+
+
+ + +
+ + +
+ @message.number@: + @message.subject@ + + +
@message.subject@ + + + +
@message.number@ + + + (response to @message.parent_number@) + +
+
+ +
+
@message.content;noquote@ + +
+ #forums.Attachments# + +
+
+
+
+ +
+
Index: openacs-4/contrib/packages/forums/lib/message/row.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/row.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/row.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,46 @@ +ad_page_contract { + + a message chunk to be included in a table listing of messages + + @author yon (yon@openforce.net) + @author arjun (arjun@openforce.net) + @creation-date 2002-06-02 + @cvs-id $Id: row.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} + +set viewer_id [ad_conn user_id] + +if {![exists_and_not_null rownum]} { + set rownum 1 +} + +set message(content) [ad_html_text_convert -from $message(format) -to text/html -- $message(content)] + +# convert emoticons to images if the parameter is set +if { [string is true [parameter::get -parameter DisplayEmoticonsAsImagesP -default 0]] } { + set message(content) [forum::format::emoticons -content $message(content)] +} + +set message(portrait_p) [dotfolio::user::portrait_p $message(user_id)] + +# JCD: display subject only if changed from the root subject +if {![info exists root_subject]} { + set display_subject_p 1 +} else { + regsub {^(Response to |\s*Re:\s*)*} $message(subject) {} subject + set display_subject_p [expr ![string equal $subject $root_subject]] +} + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} +if {![info exists message(message_id)]} { + set message(message_id) none +} +if {![info exists message(tree_level)]} { + set message(tree_level) 0 +} + +set allow_edit_own_p [parameter::get -parameter AllowUsersToEditOwnPostsP -default 0] +set own_p [expr [string equal $message(user_id) $viewer_id] && $allow_edit_own_p] \ No newline at end of file Index: openacs-4/contrib/packages/forums/lib/message/thread-chunk-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/thread-chunk-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/thread-chunk-oracle.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,59 @@ + + + + oracle8.1.6 + + + + select fma.message_id + from forums_messages fm, + forums_messages_approved fma + where fm.message_id = :root_message_id + and fma.forum_id = :forum_id + and fma.tree_sortkey between fm.tree_sortkey and tree.right(fm.tree_sortkey) + order by fma.message_id + + + + + + select message_id, + 0 as n_attachments, + subject, + content, + format, + person.name(user_id) as user_name, + to_char(posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + tree.tree_level(tree_sortkey) as tree_level, + state, + user_id, + parent_id + from $table_name + where forum_id = :forum_id + and tree_sortkey between tree.left(:tree_sortkey) and tree.right(:tree_sortkey) + order by $order_by + + + + + + select message_id, + (select count(*) from attachments where object_id = message_id) as n_attachments, + subject, + content, + format, + person.name(user_id) as user_name, + to_char(posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + tree.tree_level(tree_sortkey) as tree_level, + state, + user_id, + parent_id + from $table_name + where forum_id = :forum_id + and tree_sortkey between tree.left(:tree_sortkey) and tree.right(:tree_sortkey) + order by $order_by + + + + + Index: openacs-4/contrib/packages/forums/lib/message/thread-chunk-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/thread-chunk-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/thread-chunk-postgresql.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,62 @@ + + + + postgresql7.1 + + + + SELECT fma.message_id + FROM forums_messages_approved fma + WHERE fma.forum_id = :forum_id + and fma.tree_sortkey between (select fm.tree_sortkey from forums_messages fm where fm.message_id = :root_message_id) + and (select tree_right(fm.tree_sortkey) from forums_messages fm where fm.message_id = :root_message_id) + ORDER BY fma.message_id + + + + + + select message_id, + 0 as n_attachments, + subject, + content, + format, + person__name(user_id) as user_name, + to_char(posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + tree_level(tree_sortkey) as tree_level, + state, + user_id, + parent_id, + open_p, + max_child_sortkey + from $table_name + where forum_id = :forum_id + and tree_sortkey between tree_left(:tree_sortkey) and tree_right(:tree_sortkey) + order by $order_by + + + + + + select message_id, + (select count(*) from attachments where object_id = message_id) as n_attachments, + subject, + content, + format, + person__name(user_id) as user_name, + to_char(posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + tree_level(tree_sortkey) as tree_level, + state, + user_id, + parent_id, + open_p, + max_child_sortkey + from $table_name + where forum_id = :forum_id + and tree_sortkey between tree_left(:tree_sortkey) and tree_right(:tree_sortkey) + order by $order_by + + + + + Index: openacs-4/contrib/packages/forums/lib/message/thread-chunk.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/thread-chunk.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/thread-chunk.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,17 @@ +
+ + + + + + +
+@response_arrays_stub;noquote@ Index: openacs-4/contrib/packages/forums/lib/message/thread-chunk.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/thread-chunk.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/thread-chunk.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,152 @@ +ad_page_contract { + + view a message (and its children) + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-25 + @cvs-id $Id: thread-chunk.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} + +if {$forum(posting_policy) == "moderated"} { + set forum_moderated_p 1 +} else { + set forum_moderated_p 0 +} + +# get the colors from the params +set table_border_color [parameter::get -parameter table_border_color] +set table_bgcolor [parameter::get -parameter table_bgcolor] +set table_other_bgcolor [parameter::get -parameter table_other_bgcolor] + +# Check preferences for user + +# Set some variables for easy SQL access +set forum_id $message(forum_id) +set tree_sortkey $message(tree_sortkey) + +if {[forum::attachments_enabled_p]} { + set query select_message_responses_attachments +} else { + set query select_message_responses +} + +# We set a Tcl variable for moderation now (Ben) +if { $permissions(moderate_p) } { + set table_name "forums_messages" +} else { + set table_name "forums_messages_approved" +} + +##### +# +# Find ordering of messages +# +##### + +if { [string equal $forum(presentation_type) flat] } { + set order_by "fma.posting_date, fma.tree_sortkey" +} else { + set order_by "fma.tree_sortkey" +} + +set root_message_id $message(root_message_id) +set message_id_list [db_list select_message_ordering {}] + +set direct_url_base [export_vars -base [ad_conn url] { { message_id $message(root_message_id) } }] +set message(direct_url) "$direct_url_base\#$message(message_id)" + +set message(number) [expr [lsearch $message_id_list $message(message_id)] + 1] +set message(parent_number) {} +set message(parent_direct_url) "" +if { [exists_and_not_null message(parent_id)] } { + set message(parent_number) [expr [lsearch $message_id_list $message(parent_id)] + 1] + set message(parent_direct_url) "$direct_url_base\#$message(parent_id)" + set message(parent_root_url) [export_vars -base [ad_conn url] { { message_id $message(parent_id) } }] +} + +set message(open_p) "t" +set message(reply_p) [expr [string equal $message(open_p) "t"] || [string equal $message(user_id) [ad_conn user_id]]] +set message(tree_level) 0 + + +##### +# +# Find responses +# +##### + +# More Tcl vars (we might as well use them - Ben) +if { [string equal $forum(presentation_type) flat] } { + set order_by "$table_name.posting_date, tree_sortkey" +} else { + set order_by "tree_sortkey" +} + +set old_tree_level 0 +set old_message_id 0 +set message_ids {} + +db_multirow -extend { posting_date_pretty direct_url number parent_number parent_direct_url reply_p viewed_p open_p} responses $query {} { + set open_p t + set tree_level [min [expr {$tree_level - $message(tree_level)}] 10] + set posting_date_pretty [lc_time_fmt $posting_date_ansi "%x %X"] + set direct_url "$direct_url_base\#$message_id" + set number [expr [lsearch $message_id_list $message_id] + 1] + set parent_number [expr [lsearch $message_id_list $parent_id] + 1] + set parent_direct_url "$direct_url_base\#$parent_id" + set parent_root_url [export_vars -base [ad_conn url] {{message_id $parent_id}}] + set reply_p [expr [string equal $open_p "t"] || [string equal $user_id [ad_conn user_id]]] + + # DEDS: get the response ids the tcl way or else we need to hit + # the db for each response to count its children + if {$tree_level == 1} { + # leftmost so this is a new parent. truncate the list of ids. + set message_ids {} + } else { + if {$tree_level > $old_tree_level} { + # increase in level. previous id is a parent too. + lappend message_ids $old_message_id + foreach one_parent_id $message_ids { + lappend parent_message($one_parent_id) $message_id + } + } elseif {$tree_level < $old_tree_level} { + # decrease in level. let us pop the last id. + set message_ids_last [expr [llength $message_ids] - 1] + set message_ids [lreplace $message_ids $message_ids_last $message_ids_last] + } else { + foreach one_parent_id $message_ids { + lappend parent_message($one_parent_id) $message_id + } + } + } + # keep track of what level and message we are in + set old_tree_level $tree_level + set old_message_id $message_id + + # make sure we also populate the original message id + lappend parent_message($message(message_id)) $message_id +} + +set message(tree_level) 0 + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} + +set response_arrays_stub " +" + +set return_url [ad_return_url] Index: openacs-4/contrib/packages/forums/lib/message/threads-chunk-expanded-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/threads-chunk-expanded-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/threads-chunk-expanded-postgresql.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,62 @@ + + + postgresql7.1 + + + + select fm.message_id, + fm.subject, + person__name(fm.user_id) as user_name, + $replies as n_messages, + to_char(fm.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + case when parent_id is null then '1' else '0' end as root_message_p, + (select count(fm2.message_id) + from forums_messages_approved fm2 + where fm2.parent_id = fm.message_id) as has_children_p, + tree_level(tree_sortkey) as tree_level, + open_p + from forums_messages_approved fm + where fm.forum_id = :forum_id + order by tree_sortkey + + + + + + select fm.message_id, + fm.subject, + fm.user_id, + p.last_name||', '||p.first_names as user_name, + to_char(fm.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + fm.state, + $replies as n_messages, + to_char(fm.last_child_post, 'YYYY-MM-DD HH24:MI:SS') as last_child_post_ansi, + case when parent_id is null then '1' else '0' end as root_message_p, + (select count(fm2.message_id) + from forums_messages_approved fm2 + where fm2.parent_id = fm.message_id) as has_children_p, + tree_level(tree_sortkey) as tree_level, + open_p, + parent_id + from forums_messages_approved fm, + persons p + where fm.forum_id = :forum_id + $inclusion_clause + and fm.user_id = p.person_id + [template::list::page_where_clause -and -name messages -key fm.message_id] + order by $sortby_clause + + + + + + lower(person__name(fm.user_id)) desc + + + + + lower(person__name(fm.user_id)) asc + + + + Index: openacs-4/contrib/packages/forums/lib/message/threads-chunk-expanded.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/threads-chunk-expanded.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/threads-chunk-expanded.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,41 @@ +
+ + + + + + + +
ADD A THREAD  + + #forums.Search_colon#  +    + + +
+
+
+ + + +
+ +
+ + + + + + + + + + +
@messages.padding_nbsp;noquote@ @messages.subject@@messages.user_name@@messages.posting_date_pretty@@messages.status_info;noquote@
+
+
+
+
Index: openacs-4/contrib/packages/forums/lib/message/threads-chunk-expanded.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/threads-chunk-expanded.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/threads-chunk-expanded.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,240 @@ +ad_page_contract { + + one forum view + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-24 + @cvs-id $Id: threads-chunk-expanded.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} + +set inclusion_clause "" +set thread_p 0 + +if {![llength $expand]} { + append expand 0 +} + +switch -exact -- $viewby { + author { + set sortby_clause "lower(last_name), lower(first_names), tree_sortkey" + } + date { + set sortby_clause "fm.posting_date desc, tree_sortkey" + } + default { + set sortby_clause "last_child_post_ansi desc" + set inclusion_clause "and (fm.parent_id is null or fm.parent_id in ([join $expand ", "]))" + set thread_p 1 + } +} + +# Get forum data +forum::get -forum_id $forum_id -array forum + +form create search -action search +forums::form::search search + +if {[form is_request search]} { + element set_properties search forum_id -value $forum_id +} + + +if { $moderate_p } { + set replies reply_count +} else { + set replies approved_reply_count +} + +set actions [list] +if {![exists_and_not_null return_url]} { + set return_url [ad_return_url] +} + +# new postings are allowed if + +# 1. Users can create new threads AND the posting policy is open or moderated +# 2. User is a moderator or adminsitrator + +if {([forum::new_questions_allowed_p -forum_id $forum_id] && ($forum(posting_policy) == "open" || $forum(posting_policy) == "moderated")) || [template::util::is_true $permissions(admin_p)] || [template::util::is_true $permissions(moderate_p)] } { + lappend actions [_ forums.Post_a_New_Message] [export_vars -base "message-post" { forum_id }] {} + set show_post_p 1 +} + +if { [template::util::is_true $permissions(admin_p)] } { + lappend actions [_ forums.Administer] [export_vars -base "admin/forum-edit" { forum_id {return_url [ad_return_url]}}] {} +} + +if { [template::util::is_true $permissions(moderate_p)] } { + lappend actions [_ forums.ManageModerate] [export_vars -base "moderate/forum" { forum_id }] {} +} + +template::list::create \ + -name messages \ + -multirow messages \ + -pass_properties { moderate_p } \ + -elements { + subject { + label "#forums.Subject#" + link_url_col message_url + display_template { + @messages.subject@ + @messages.subject@ + } + } + state_pretty { + label "\#forums.Moderate\#" + hide_p {[ad_decode $moderate_p 1 0 1]} + } + user_name { + label "#forums.Author#" + link_url_col user_url + } + posting_date { + label "#forums.First_Post#" + display_col posting_date_pretty + } + } -filters { + forum_id {} + } + + +# DEDS: odd even logic for pbs goes here +# this can actually be done using the db +# but that means calling the plsql to get the +# root message id for comparison which could +# slow it down +set odd_even_ctr 1 +set open_nodes {} + +multirow create messages message_id subject user_id user_name posting_date_ansi state n_messages last_child_post_ansi root_message_p has_children_p tree_level open_p new_p parent_id last_child_post_pretty posting_date_pretty message_url user_url n_messages_pretty state_pretty odd_even padding_nbsp status_info action_url image_url onclick + +db_foreach messages_select {} { + if { [lsearch -exact $open_nodes $parent_id] == -1 && $parent_id != "" && $thread_p } { continue } + + set last_child_post_ansi [lc_time_system_to_conn $last_child_post_ansi] + set last_child_post_pretty [lc_time_fmt $last_child_post_ansi "%x %X"] + + set posting_date_ansi [lc_time_system_to_conn $posting_date_ansi] + set posting_date_pretty [lc_time_fmt $posting_date_ansi "%x %X"] + + set message_url [export_vars -base "message-view" { message_id return_url }] + set user_url [export_vars -base "user-history" { user_id }] + set n_messages_pretty [lc_numeric $n_messages] + + switch $state { + pending { + set state_pretty [_ forums.Pending] + } + rejected { + set state_pretty [_ forums.Rejected] + } + default { + set state_pretty {} + } + } + if {$root_message_p || !$thread_p} { + # this is a new root message, switch the odd even row + set odd_even_ctr [expr ($odd_even_ctr + 1) % 2] + } + if {$odd_even_ctr} { + set odd_even odd + } else { + set odd_even even + } + if {$thread_p} { + set padding_nbsp [string repeat " " [expr ($tree_level - 1) * 2]] + } else { + set padding_nbsp "" + } + set status_info_list [list] + if {[string equal $open_p f]} { + lappend status_info_list "LOCKED" + } + if {![views::viewed_p -object_id $message_id]} { + set new_p t + lappend status_info_list "NEW" + } else { + set new_p f + } + + set my_expansion [lreplace $expand [lsearch $expand 0] [lsearch $expand 0]] + + set status_info [join $status_info_list " | "] + if {$has_children_p && $thread_p} { + set mindex [lsearch $expand $message_id] + if {[empty_string_p $parent_id] || ([lsearch $open_nodes $parent_id] != -1)} { + if {$mindex == -1} { + lappend my_expansion $message_id + set image_url "/resources/forums/button_blue_expand.gif" + } else { + lappend open_nodes $message_id + set image_url "/resources/forums/button_blue_collapsed.gif" + set my_expansion [lreplace $expand $mindex $mindex] + } + } + + set updatediv [ah::ajaxupdate -container "replies${message_id}" \ + -url "xmlhttp/getreplies" \ + -pars "'message_id=${message_id}&odd_even=${odd_even}'"] + + set onclick [ah::toggle -element "tr${message_id}" \ + -effect "Blind" \ + -options "duration:1.0, + beforeStart:function() { + var str = \$('img${message_id}').src; + if ( str.search('button_blue_expand.gif') != -1 ) { + ${updatediv} + \$('img${message_id}').src = '/resources/forums/button_blue_collapsed.gif'; + } else { + \$('img${message_id}').src = '/resources/forums/button_blue_expand.gif'; + } + } + " ] + + + } else { + set image_url "" + set onclick "" + } + + set action_url [export_vars -base "forum-view" {forum_id {expand:multiple $my_expansion}}] + + multirow append messages $message_id $subject $user_id $user_name $posting_date_ansi $state $n_messages $last_child_post_ansi $root_message_p $has_children_p $tree_level $open_p $new_p $parent_id $last_child_post_pretty $posting_date_pretty $message_url $user_url $n_messages_pretty $state_pretty $odd_even $padding_nbsp $status_info $action_url $image_url $onclick +} + + +# get clipboard info +#clipboard::clipboards -create_new -force_default [ad_conn user_id] clipboards +#clipboard::clipboards -force_default [ad_conn user_id] user_clipboards + +if {[empty_string_p $viewby]} { + # user doesn't set display so let's get cookie + set viewby [ad_get_cookie forums_display_mode thread] +} else { + # user desires a new look so store it too + # half a year should be fine for now + ad_set_cookie -replace t -max_age 15768000 forums_display_mode $viewby +} + + set display_options_list {{Thread thread} {Author author} {Date date}} + ad_form \ + -name display_form \ + -method post \ + -has_submit 1 \ + -form { + {forum_id:text(hidden) {value $forum_id}} + {viewby:text(select) + {label "Sort By:"} + {options $display_options_list} + {value $viewby} + {html {onChange "this.form.submit();"}} + } + } \ + -after_submit { + } + +set this_return_url [ad_return_url] +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} Index: openacs-4/contrib/packages/forums/lib/message/threads-chunk-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/threads-chunk-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/threads-chunk-oracle.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,50 @@ + + + oracle8.1.6 + + + + select fm.message_id, + fm.subject, + person.name(fm.user_id) as user_name, + to_char(fm.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + $replies as n_messages, + to_char(fm.last_child_post, 'YYYY-MM-DD HH24:MI:SS') as last_child_post_ansi + from forums_messages_approved fm + where fm.forum_id = :forum_id + and fm.parent_id is null + [template::list::orderby_clause -orderby -name "messages"] + + + + + + select fm.message_id, + fm.subject, + fm.user_id, + person.name(fm.user_id) as user_name, + to_char(fm.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + fm.state, + $replies as n_messages, + to_char(fm.last_child_post, 'YYYY-MM-DD HH24:MI:SS') as last_child_post_ansi, + case when fm.last_child_post > (sysdate - 1) then 't' else 'f' end as new_p + from forums_messages_approved fm + where fm.forum_id = :forum_id + and fm.parent_id is null + [template::list::page_where_clause -and -name messages -key fm.message_id] + [template::list::orderby_clause -orderby -name "messages"] + + + + + + user_name desc + + + + + user_name asc + + + + Index: openacs-4/contrib/packages/forums/lib/message/threads-chunk-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/threads-chunk-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/threads-chunk-postgresql.xql 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,49 @@ + + + postgresql7.1 + + + + select fm.message_id, + fm.subject, + person__name(fm.user_id) as user_name, + $replies as n_messages, + to_char(fm.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi + from forums_messages_approved fm + where fm.forum_id = :forum_id + and fm.parent_id is null + [template::list::orderby_clause -orderby -name messages] + + + + + + select fm.message_id, + fm.subject, + fm.last_poster as user_id, + person__name(fm.last_poster) as user_name, + to_char(fm.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + fm.state, + $replies as n_messages, + to_char(fm.last_child_post, 'YYYY-MM-DD HH24:MI:SS') as last_child_post_ansi, + case when fm.last_child_post > (now() - interval '1 day') then 't' else 'f' end as new_p + from forums_messages_approved fm + where fm.forum_id = :forum_id + and fm.parent_id is null + [template::list::page_where_clause -and -name messages -key fm.message_id] + [template::list::orderby_clause -orderby -name messages] + + + + + + lower(person__name(fm.last_poster)) desc + + + + + lower(person__name(fm.last_poster)) asc + + + + Index: openacs-4/contrib/packages/forums/lib/message/threads-chunk.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/threads-chunk.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/threads-chunk.adp 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1 @@ + Index: openacs-4/contrib/packages/forums/lib/message/threads-chunk.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/message/Attic/threads-chunk.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/message/threads-chunk.tcl 23 Jan 2007 13:24:03 -0000 1.1 @@ -0,0 +1,140 @@ +ad_page_contract { + + one forum view + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-24 + @cvs-id $Id: threads-chunk.tcl,v 1.1 2007/01/23 13:24:03 hamiltonc Exp $ + +} + +# Get forum data +forum::get -forum_id $forum_id -array forum + +if { $moderate_p } { + set replies reply_count +} else { + set replies approved_reply_count +} + +set actions [list] + +# new postings are allowed if + +# 1. Users can create new threads AND the posting policy is open or moderated +# 2. User is a moderator or adminsitrator + +if {([forum::new_questions_allowed_p -forum_id $forum_id] && ($forum(posting_policy) == "open" || $forum(posting_policy) == "moderated")) || [template::util::is_true $permissions(admin_p)] || [template::util::is_true $permissions(moderate_p)] } { + lappend actions [_ forums.Post_a_New_Message] [export_vars -base "message-post" { forum_id }] {} +} + +if { [template::util::is_true $permissions(admin_p)] } { + lappend actions [_ forums.Administer] [export_vars -base "admin/forum-edit" { forum_id {return_url [ad_return_url]}}] {} + lappend actions [_ forums.Subscribe_others] [export_vars -base "admin/subscribe-others" { forum_id {return_url [ad_return_url]}}] {} +} + +if { [template::util::is_true $permissions(moderate_p)] } { + lappend actions [_ forums.ManageModerate] [export_vars -base "moderate/forum" { forum_id }] {} +} + +template::list::create \ + -name messages \ + -multirow messages \ + -page_size 30 \ + -page_query_name messages_select_paginate \ + -pass_properties { moderate_p } \ + -actions $actions \ + -elements { + subject { + label "#forums.Subject#" + link_url_col message_url + display_template { + @messages.subject@ + @messages.subject@ + } + } + state_pretty { + label "\#forums.Moderate\#" + hide_p {[ad_decode $moderate_p 1 0 1]} + } + user_name { + label "#forums.Author#" + link_url_col user_url + } + n_messages { + label "#forums.Replies#" + display_col n_messages_pretty + html { align right } + } + posting_date { + label "#forums.First_Post#" + display_col posting_date_pretty + } + last_child_post { + label "#forums.Last_Post#" + display_col last_child_post_pretty + } + } -orderby { + posting_date { + label "#forums.First_Post#" + orderby posting_date + default_direction desc + } + last_child_post { + label "#forums.Last_Post#" + orderby last_child_post + default_direction desc + } + subject { + label "#forums.Subject#" + orderby upper(subject) + } + user_name { + label "#forums.Author#" + orderby_asc_name "orderby_user_name_asc" + orderby_desc_name "orderby_user_name_desc" + } + n_messages { + label "#forums.Replies#" + orderby_asc {n_messages asc, posting_date desc} + orderby_desc {n_messages desc, posting_date desc} + } + } -filters { + forum_id {} + } + +db_multirow -extend { + last_child_post_pretty + posting_date_pretty + message_url + user_url + n_messages_pretty + state_pretty +} messages messages_select {} { + set last_child_post_ansi [lc_time_system_to_conn $last_child_post_ansi] + set last_child_post_pretty [lc_time_fmt $last_child_post_ansi "%x %X"] + + set posting_date_ansi [lc_time_system_to_conn $posting_date_ansi] + set posting_date_pretty [lc_time_fmt $posting_date_ansi "%x %X"] + + set message_url [export_vars -base "message-view" { message_id }] + set user_url [export_vars -base "user-history" { user_id }] + set n_messages_pretty [lc_numeric $n_messages] + + switch $state { + pending { + set state_pretty [_ forums.Pending] + } + rejected { + set state_pretty [_ forums.Rejected] + } + default { + set state_pretty {} + } + } +} + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} + Index: openacs-4/contrib/packages/forums/lib/search/search-chunk-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/search/Attic/search-chunk-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/search/search-chunk-oracle.xql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,76 @@ + + + + oracle8.1.6 + + + + select forums_messages.*, + person.name(forums_messages.user_id) as user_name, + to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + 100 as the_score + from forums_messages, + forums_forums + where forums_messages.forum_id = forums_forums.forum_id + and forums_forums.package_id = :package_id + and forums_messages.state = 'approved' + and upper(forums_messages.subject || ' ' || dbms_lob.substr(forums_messages.content,2500) || ' ' || person.name(forums_messages.user_id)) + like '%' || upper(:search_text) || '%' + order by forums_messages.posting_date desc + + + + + + select forums_messages.*, + person.name(forums_messages.user_id) as user_name, + to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + 100 as the_score + from forums_messages, + forums_forums + where forums_forums.forum_id = :forum_id + and forums_forums.package_id = :package_id + and forums_messages.forum_id = forums_forums.forum_id + and forums_messages.state = 'approved' + and upper(forums_messages.subject || ' ' || dbms_lob.substr(forums_messages.content,3500) || ' ' || person.name(forums_messages.user_id)) + like '%' || upper(:search_text) || '%' + order by forums_messages.posting_date desc + + + + + + select forums_messages.*, + person.name(forums_messages.user_id) as user_name, + to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + score(1) as the_score + from forums_messages, + forums_forums + where forums_messages.forum_id = forums_forums.forum_id + and forums_forums.package_id = :package_id + and forums_messages.state = 'approved' + and contains(forums_messages.content, '%' || :search_text || '%', 1) > 0 + order by the_score desc, + forums_messages.posting_date desc + + + + + + select forums_messages.*, + person.name(forums_messages.user_id) as user_name, + to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + score(1) as the_score + from forums_messages, + forums_forums + where forums_forums.forum_id = :forum_id + and forums_forums.package_id = :package_id + and forums_messages.forum_id = forums_forums.forum_id + and forums_messages.state = 'approved' + and contains(forums_messages.content, '%' || :search_text || '%', 1) > 0 + order by the_score desc, + forums_messages.posting_date desc + + + + Index: openacs-4/contrib/packages/forums/lib/search/search-chunk-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/search/Attic/search-chunk-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/search/search-chunk-postgresql.xql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,41 @@ + + + + postgresql7.1 + + + + select forums_messages.*, + person__name(forums_messages.user_id) as user_name, + to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + 100 as the_score + from forums_messages, + forums_forums + where forums_messages.forum_id = forums_forums.forum_id + and forums_forums.package_id = :package_id + and forums_messages.state = 'approved' + and upper(forums_messages.subject || ' ' || forums_messages.content || ' ' || person__name(forums_messages.user_id)) + like '%' || upper(:search_text) || '%' + order by forums_messages.posting_date desc + + + + + + select forums_messages.*, + person__name(forums_messages.user_id) as user_name, + to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + 100 as the_score + from forums_messages, + forums_forums + where forums_forums.forum_id = :forum_id + and forums_forums.package_id = :package_id + and forums_messages.forum_id = forums_forums.forum_id + and forums_messages.state = 'approved' + and upper(forums_messages.subject || ' ' || forums_messages.content || ' ' || person__name(forums_messages.user_id)) + like '%' || upper(:search_text) || '%' + order by forums_messages.posting_date desc + + + + Index: openacs-4/contrib/packages/forums/lib/search/search-chunk.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/search/Attic/search-chunk.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/search/search-chunk.adp 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,15 @@ + + + + + +
+ + #forums.Search#  + +
+ +
+ + +
Index: openacs-4/contrib/packages/forums/lib/search/search-chunk.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/search/Attic/search-chunk.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/search/search-chunk.tcl 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,42 @@ +ad_page_contract { + + @author yon@openforce.net + @creation-date 2002-07-01 + @cvs-id $Id: search-chunk.tcl,v 1.1 2007/01/23 13:24:04 hamiltonc Exp $ + +} +set package_id [ad_conn package_id] + +set searchbox_p [parameter::get -parameter ForumsSearchBoxP -package_id $package_id -default 1] +if {$searchbox_p} { + form create search + forums::form::search search + + if {[form is_valid search]} { + form get_values search search_text forum_id + + # remove any special characters from the search text so we + # don't crash interMedia + regsub -all {[^[:alnum:]_[:blank:]]} $search_text {} search_text + + set query search_all_forums + if {![empty_string_p $forum_id]} { + set query search_one_forum + } + + if { [parameter::get -parameter UseIntermediaForSearchP -default 0] } { + append query "_intermedia" + } + + db_multirow messages $query {} { + set posting_date [lc_time_fmt $posting_date_ansi "%x %X"] + } + + } else { + set messages:rowcount 0 + } + + if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template + } +} \ No newline at end of file Index: openacs-4/contrib/packages/forums/lib/search/top-search-chunk.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/search/Attic/top-search-chunk.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/search/top-search-chunk.adp 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,17 @@ +
+ + + + + + + +
ADD A DISCUSSION  + + #forums.Search_colon#  +    + + +
+
+
Index: openacs-4/contrib/packages/forums/lib/search/top-search-chunk.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/search/Attic/top-search-chunk.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/search/top-search-chunk.tcl 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,14 @@ +if { ! [exists_and_not_null package_id] } { + set package_id [ad_conn package_id] +} +set user_id [ad_conn user_id] +set admin_p [permission::permission_p -party_id $user_id -object_id $package_id -privilege admin] +set searchbox_p [parameter::get -parameter ForumsSearchBoxP -package_id $package_id -default 1] + +set package_url [site_node::get_url_from_object_id -object_id $package_id] + +# Create a search form and action when used +if {$searchbox_p} { + form create search -action ${package_url}search + forums::form::search search +} Index: openacs-4/contrib/packages/forums/lib/user/post-history-chunk.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/user/Attic/post-history-chunk.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/user/post-history-chunk.adp 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,138 @@ +

+ #forums.Posting_history_for# + + <% + if {![permission::permission_p -object_id [acs_magic_object security_context_root] -privilege admin]} { + adp_puts [acs_community_member_link -user_id $user_id] + } else { + adp_puts [acs_community_member_admin_link -user_id $user_id] + } + %> + +

+ +

+

+@dimensional_chunk;noquote@ +
+

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#forums.Forum##forums.Subject##forums.Posted#
@messages.forum_name@@messages.subject@@messages.posting_date_pretty@
+ #forums.No_Postings# +
+

+
+

#forums.Summary_Posting_history_for#

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#forums.Forum##forums.Number_of_Posts##forums.Posted#
@posts.name@@posts.num_msg@@posts.last_post@
+ #forums.No_Postings# +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@messages.forum_name@

#forums.Subject##forums.Posted#
@messages.subject@@messages.posting_date_pretty@
+
+ +
+ +
+ +
Index: openacs-4/contrib/packages/forums/lib/user/post-history-chunk.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/user/Attic/post-history-chunk.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/user/post-history-chunk.tcl 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,45 @@ +ad_page_contract { + + Posting History for a User + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-29 + @cvs-id $Id: post-history-chunk.tcl,v 1.1 2007/01/23 13:24:04 hamiltonc Exp $ + +} + +set package_id [ad_conn package_id] + +# get the colors from the params +set table_border_color [parameter::get -parameter table_border_color] +set table_bgcolor [parameter::get -parameter table_bgcolor] +set table_other_bgcolor [parameter::get -parameter table_other_bgcolor] + +# choosing the view +set dimensional_list " + { + view \"[_ forums.View]:\" date { + {date \"[_ forums.by_Date]\" {}} + {forum \"[_ forums.by_Forum]\" {}} + } + } +" + +set query select_messages +if {[string equal $view forum]} { + set query select_messages_by_forum +} + +# Select the postings +db_multirow -extend { posting_date_pretty } messages $query {} { + set posting_date_pretty [lc_time_fmt $posting_date_ansi "%x %X"] +} + +# select number of post from this user +db_multirow posts select_num_post {} + +set dimensional_chunk [ad_dimensional $dimensional_list] + +if {[exists_and_not_null alt_template]} { + ad_return_template $alt_template +} Index: openacs-4/contrib/packages/forums/lib/user/post-history-chunk.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/lib/user/Attic/post-history-chunk.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/lib/user/post-history-chunk.xql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,48 @@ + + + + + + + select forums_messages.message_id, + forums_messages.subject, + to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + forums_forums.forum_id, + forums_forums.name as forum_name + from forums_messages, + forums_forums + where forums_messages.user_id = :user_id + and forums_messages.forum_id = forums_forums.forum_id + and forums_forums.package_id = :package_id + order by forums_messages.posting_date desc + + + + + + select forums_messages.message_id, + forums_messages.subject, + to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi, + forums_forums.forum_id, + forums_forums.name as forum_name + from forums_messages, + forums_forums + where forums_messages.user_id = :user_id + and forums_messages.forum_id = forums_forums.forum_id + and forums_forums.package_id = :package_id + order by forum_name, + forums_messages.posting_date desc + + + + + + select count(user_id) as num_msg, to_char(max(last_child_post), 'YYYY-MM-DD HH24:MI:SS') as last_post, forums_forums.name, forums_forums.forum_id + from forums_messages, forums_forums + where forums_messages.user_id = :user_id and forums_forums.forum_id = forums_messages.forum_id and package_id = :package_id + group by forums_forums.name, forums_forums.forum_id + order by forums_forums.name asc + + + + Index: openacs-4/contrib/packages/forums/sql/oracle/forums-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-create.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,24 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert's UBB forums. Thanks Orchard Labs. +-- + +-- The basic forum constructs +@ forums-forums-create.sql +@ forums-forums-package-create.sql + +-- The messages +@ forums-messages-create.sql +@ forums-messages-package-create.sql + +-- tree stuff +@ forums-tree-create.sql + +-- notifications +@ forums-notifications-init.sql Index: openacs-4/contrib/packages/forums/sql/oracle/forums-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-drop.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,24 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert's UBB forums. Thanks Orchard Labs. +-- + +-- notifications +@ forums-notifications-sanitize.sql + +-- tree stuff +@ forums-tree-drop.sql + +-- The messages +@ forums-messages-drop.sql +@ forums-messages-package-drop.sql + +-- The basic forum constructs +@ forums-forums-drop.sql +@ forums-forums-package-drop.sql Index: openacs-4/contrib/packages/forums/sql/oracle/forums-forums-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-forums-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-forums-create.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,89 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs. +-- + +-- privileges +declare +begin + -- The standard privilege 'admin' on a package allows a user to + -- create forums (enforced by URL). + -- The standard privilege 'create' on a forum allows a user to + -- create new threads. + -- The standard privilege 'write' on a message allows a user to + -- post a follow up message. + + -- forum_moderate lets us grant moderation without granting full admin + acs_privilege.create_privilege('forum_moderate',null,null); + acs_privilege.add_child('admin','forum_moderate'); + acs_privilege.add_child('forum_moderate','create'); + acs_privilege.add_child('forum_moderate','delete'); + acs_privilege.add_child('forum_moderate','read'); + acs_privilege.add_child('forum_moderate','write'); + +end; +/ +show errors + +create table forums_forums ( + forum_id integer + constraint forums_forum_id_fk + references acs_objects (object_id) + constraint forums_forums_pk + primary key, + name varchar(200) + constraint forums_name_nn + not null, + charter varchar(4000), + presentation_type varchar(100) + constraint forums_presentation_type_nn + not null + constraint forums_presentation_type_ck + check (presentation_type in ('flat','threaded')), + posting_policy varchar(100) + constraint forums_posting_policy_nn + not null + constraint forums_posting_policy_ck + check (posting_policy in ('open','moderated','closed')), + max_child_sortkey raw(100), + enabled_p char(1) + default 't' + constraint forums_enabled_p_nn + not null + constraint forums_enabled_p_ck + check (enabled_p in ('t','f')), + package_id integer + constraint forums_package_id_nn + not null, + thread_count integer default 0, + approved_thread_count integer default 0, + last_post date +); + +create view forums_forums_enabled +as + select * + from forums_forums + where enabled_p = 't'; + +declare +begin + acs_object_type.create_type( + supertype => 'acs_object', + object_type => 'forums_forum', + pretty_name => 'Forums Forum', + pretty_plural => 'Forums Forums', + table_name => 'forums_forums', + id_column => 'forum_id', + package_name => 'forums_forum', + name_method => 'forums_forum.name' + ); +end; +/ +show errors Index: openacs-4/contrib/packages/forums/sql/oracle/forums-forums-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-forums-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-forums-drop.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,62 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs. +-- + +-- privileges +declare +begin + + delete from acs_permissions where privilege in ('forum_moderate'); + + -- remove children + acs_privilege.remove_child('admin','forum_moderate'); + acs_privilege.remove_child('forum_moderate','create'); + acs_privilege.remove_child('forum_moderate','delete'); + acs_privilege.remove_child('forum_moderate','read'); + acs_privilege.remove_child('forum_moderate','write'); + + acs_privilege.drop_privilege('forum_moderate'); +end; +/ +show errors + + +-- +-- The Data Model +-- + +drop view forums_forums_enabled; + +drop table forums_forums; + +-- +-- Object Type +-- + +declare + v_object_id integer; +begin + + select MAX(object_id) into v_object_id from acs_objects where object_type='forums_forum'; + While (v_object_id > 0) loop + delete from ncanotes where object_id=v_object_id; + acs_object.del( + v_object_id -- object_id + ); + select MAX(object_id) into v_object_id from acs_objects where object_type='forums_forum'; + End loop; + + acs_object_type.drop_type ( + object_type => 'forums_forum' + ); + +end; +/ +show errors Index: openacs-4/contrib/packages/forums/sql/oracle/forums-forums-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-forums-package-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-forums-package-create.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,105 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- The Package +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs! +-- + +create or replace package forums_forum +as + + function new ( + forum_id in forums_forums.forum_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_forum', + name in forums_forums.name%TYPE, + charter in forums_forums.charter%TYPE default null, + presentation_type in forums_forums.presentation_type%TYPE, + posting_policy in forums_forums.posting_policy%TYPE, + package_id in forums_forums.package_id%TYPE, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_forums.forum_id%TYPE; + + function name ( + forum_id in forums_forums.forum_id%TYPE + ) return varchar; + + procedure del ( + forum_id in forums_forums.forum_id%TYPE + ); + +end forums_forum; +/ +show errors + +create or replace package body forums_forum +as + + function new ( + forum_id in forums_forums.forum_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_forum', + name in forums_forums.name%TYPE, + charter in forums_forums.charter%TYPE default null, + presentation_type in forums_forums.presentation_type%TYPE, + posting_policy in forums_forums.posting_policy%TYPE, + package_id in forums_forums.package_id%TYPE, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_forums.forum_id%TYPE + is + v_forum_id forums_forums.forum_id%TYPE; + begin + v_forum_id := acs_object.new( + object_id => forum_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => nvl(context_id, package_id), + package_id => forums_forum.new.package_id, + title => name + ); + + insert into forums_forums + (forum_id, name, charter, presentation_type, posting_policy, package_id) + values + (v_forum_id, name, charter, presentation_type, posting_policy, package_id); + + return v_forum_id; + end new; + + function name ( + forum_id in forums_forums.forum_id%TYPE + ) return varchar + is + v_name forums_forums.name%TYPE; + begin + select name + into v_name + from forums_forums + where forum_id = name.forum_id; + + return v_name; + end name; + + procedure del ( + forum_id in forums_forums.forum_id%TYPE + ) + is + begin + acs_object.del(forum_id); + end del; + +end forums_forum; +/ +show errors Index: openacs-4/contrib/packages/forums/sql/oracle/forums-forums-package-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-forums-package-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-forums-package-drop.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,15 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- The Package +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs! +-- +-- drop script + +drop package forums_forum; Index: openacs-4/contrib/packages/forums/sql/oracle/forums-messages-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-messages-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-messages-create.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,95 @@ +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert. Thanks Orchard Labs! +-- + +create table forums_messages ( + message_id integer + constraint forums_message_id_fk + references acs_objects (object_id) + constraint forums_messages_pk + primary key, + forum_id integer + constraint forums_mess_forum_id_fk + references forums_forums (forum_id), + subject varchar(200), + content clob, + user_id integer + constraint forums_mess_user_id_fk + references users(user_id) + constraint forums_mess_user_id_nn + not null, + posting_date date + default sysdate + constraint forum_mess_post_date_nn + not null, + state varchar(100) + constraint forum_mess_state_ck + check (state in ('pending','approved','rejected')), + format varchar2(30) + default 'text/plain', + -- Hierarchy of messages + parent_id integer + constraint forum_mess_parent_id_fk + references forums_messages (message_id), + open_p char(1) + default 't' + constraint forum_mess_open_p_nn + not null + constraint forum_mess_open_p_ck + check (open_p in ('t','f')), + tree_sortkey raw(240), + max_child_sortkey raw(100), + last_child_post date, + reply_count integer default 0 + constraint forums_mess_reply_count_ck + check (reply_count >= 0), + approved_reply_count integer default 0 + constraint forums_mess_app_rep_count_ck + check (approved_reply_count >= 0), + last_poster integer + constraint forums_mess_last_poster_fk + references users(user_id), + constraint forums_mess_sk_forum_un + unique (tree_sortkey, forum_id) +); + +-- We do a some big queries on forum_id (thread count on index.tcl) so create a second index +-- ordered so it's useful for them +create unique index forums_mess_forum_sk_un on forums_messages(forum_id, tree_sortkey); +-- Need these for RI checks +create index forums_messages_user_id_idx on forums_messages(user_id); +create index forums_messages_parent_id_idx on forums_messages(parent_id); +create index forum_messages_date_idx on forums_messages (forum_id, posting_date) compress 1; + + +create view forums_messages_approved as + select * + from forums_messages + where state = 'approved'; + +create view forums_messages_pending as + select * + from forums_messages + where state = 'pending'; + +declare +begin + acs_object_type.create_type ( + supertype => 'acs_object', + object_type => 'forums_message', + pretty_name => 'Forums Message', + pretty_plural => 'Forums Messages', + table_name => 'forums_messages', + id_column => 'message_id', + package_name => 'forums_message', + name_method => 'forums_message.name' + ); +end; +/ +show errors Index: openacs-4/contrib/packages/forums/sql/oracle/forums-messages-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-messages-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-messages-drop.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,36 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert. Thanks Orchard Labs! +-- + +-- privileges +-- NO PRIVILEGES FOR MESSAGES +-- we don't individually permission messages + +-- +-- The Data Model +-- + +drop table forums_messages; + +-- +-- Object Type +-- + +declare +begin + acs_object_type.drop_type ( + object_type => 'forums_message' + ); +end; +/ +show errors + +drop view forums_messages_pending; +drop view forums_messages_approved; \ No newline at end of file Index: openacs-4/contrib/packages/forums/sql/oracle/forums-messages-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-messages-package-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-messages-package-create.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,384 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- The Package for Messages +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs! +-- + +create or replace package forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + format in forums_messages.format%TYPE default 'text/plain', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ); + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ); + + procedure del ( + message_id in forums_messages.message_id%TYPE + ); + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ); + + procedure set_state( + message_id in forums_messages.message_id%TYPE, + state in forums_messages.state%TYPE + ); + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar; + +end forums_message; +/ +show errors + +create or replace package body forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + format in forums_messages.format%TYPE default 'text/plain', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE + is + v_message_id acs_objects.object_id%TYPE; + v_package_id acs_objects.package_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; + begin + select package_id into v_package_id from forums_forums where forum_id = new.forum_id; + + v_message_id := acs_object.new( + object_id => message_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => nvl(context_id, forum_id), + title => subject, + package_id => v_package_id + ); + + if state is null + then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id= new.forum_id; + + if v_forum_policy = 'moderated' then + v_state := 'pending'; + else + v_state := 'approved'; + end if; + else + v_state := state; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, format, user_id, posting_date, last_child_post, parent_id, state, last_poster) + values + (v_message_id, forum_id, subject, content, format, user_id, posting_date, posting_date, parent_id, v_state, user_id); + + select tree_sortkey into v_sortkey + from forums_messages + where message_id = v_message_id; + + update forums_forums + set last_post = forums_message.new.posting_date + where forum_id = forums_message.new.forum_id; + + -- DRB: Can't use root_message_id() here because it triggers a "mutating table" error + + if parent_id is null then + if v_state = 'approved' then + update forums_forums + set thread_count = thread_count + 1, + approved_thread_count = approved_thread_count + 1 + where forum_id = forums_message.new.forum_id; + else + update forums_forums + set thread_count = thread_count + 1 + where forum_id=forums_message.new.forum_id; + end if; + else + if v_state = 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count + 1, + reply_count = reply_count + 1, + last_poster = forums_message.new.user_id, + last_child_post = forums_message.new.posting_date + where forum_id = forums_message.new.forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + else + update forums_messages + set reply_count = reply_count + 1 + where forum_id = forums_message.new.forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + end if; + end if; + + return v_message_id; + + end new; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE + is + v_message_id forums_messages.message_id%TYPE; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = root_message_id.message_id; + + select message_id + into v_message_id + from forums_messages + where forum_id = v_forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + + return v_message_id; + end root_message_id; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_open.message_id; + + update forums_messages + set open_p = 't' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 't' + where message_id = thread_open.message_id; + end thread_open; + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_close.message_id; + + update forums_messages + set open_p = 'f' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 'f' + where message_id = thread_close.message_id; + end thread_close; + + procedure del ( + message_id in forums_messages.message_id%TYPE + ) + is + v_cur forums_messages%ROWTYPE; + begin + + -- Maintain the forum thread counts + + select * into v_cur + from forums_messages + where message_id = forums_message.del.message_id; + + if v_cur.parent_id is null then + if v_cur.state = 'approved' then + update forums_forums + set thread_count = thread_count - 1, + approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + else + update forums_forums + set thread_count = thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + elsif v_cur.state = 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count - 1, + reply_count = reply_count - 1 + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + else + update forums_messages + set reply_count = reply_count - 1 + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + end if; + + acs_object.del(message_id); + + end del; + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_message forums_messages%ROWTYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = delete_thread.message_id; + + -- if it's already deleted + if SQL%NOTFOUND then + return; + end if; + + -- delete all children + -- order by tree_sortkey desc to guarantee + -- that we never delete a parent before its child + -- sortkeys are beautiful + for v_message in (select * + from forums_messages + where forum_id = v_forum_id + and tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + order by tree_sortkey desc) + loop + forums_message.del(v_message.message_id); + end loop; + + -- delete the message itself + forums_message.del(delete_thread.message_id); + end delete_thread; + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar + is + v_name forums_messages.subject%TYPE; + begin + select subject + into v_name + from forums_messages + where message_id = forums_message.name.message_id; + + return v_name; + end name; + + procedure set_state( + message_id in forums_messages.message_id%TYPE, + state in forums_messages.state%TYPE + ) + is + v_cur forums_messages%ROWTYPE; + v_last_child_post forums_messages.last_child_post%TYPE; + begin + + select * into v_cur + from forums_messages + where message_id = forums_message.set_state.message_id; + + if v_cur.parent_id is null then + if state = 'approved' and v_cur.state <> 'approved' then + update forums_forums + set approved_thread_count = approved_thread_count + 1 + where forum_id=v_cur.forum_id; + elsif state <> 'approved' and v_cur.state = 'approved' then + update forums_forums + set approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + else + if state = 'approved' and v_cur.state <> 'approved' then + select last_child_post into v_last_child_post + from forums_messages + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + if v_cur.posting_date > v_last_child_post then + update forums_messages + set approved_reply_count = approved_reply_count + 1, + last_poster = v_cur.user_id, + last_child_post = v_cur.posting_date + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + else + update forums_messages + set approved_reply_count = approved_reply_count + 1 + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + end if; + elsif state <> 'approved' and v_cur.state = 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count - 1 + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + end if; + end if; + + update forums_messages + set state = forums_message.set_state.state + where message_id = forums_message.set_state.message_id; + + end set_state; + +end forums_message; +/ +show errors + Index: openacs-4/contrib/packages/forums/sql/oracle/forums-messages-package-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-messages-package-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-messages-package-drop.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,14 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- The Package for Messages +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs! +-- + +drop package forums_message; Index: openacs-4/contrib/packages/forums/sql/oracle/forums-notifications-init.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-notifications-init.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-notifications-init.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,118 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert's UBB forums. Thanks Orchard Labs. +-- + +-- the integration with Notifications + +declare + impl_id integer; + v_foo integer; +begin + -- the notification type impl + impl_id := acs_sc_impl.new ( + impl_contract_name => 'NotificationType', + impl_name => 'forums_forum_notif_type', + impl_pretty_name => 'forums_forum_notif_type', + impl_owner_name => 'forums' + ); + + v_foo := acs_sc_impl.new_alias ( + 'NotificationType', + 'forums_forum_notif_type', + 'GetURL', + 'forum::notification::get_url', + 'TCL' + ); + + v_foo := acs_sc_impl.new_alias ( + 'NotificationType', + 'forums_forum_notif_type', + 'ProcessReply', + 'forum::notification::process_reply', + 'TCL' + ); + + acs_sc_binding.new ( + contract_name => 'NotificationType', + impl_name => 'forums_forum_notif_type' + ); + + v_foo:= notification_type.new ( + short_name => 'forums_forum_notif', + sc_impl_id => impl_id, + pretty_name => 'Forum Notification', + description => 'Notifications for Entire Forums', + creation_user => NULL, + creation_ip => NULL + ); + + -- enable the various intervals and delivery methods + insert into notification_types_intervals + (type_id, interval_id) + select v_foo, interval_id + from notification_intervals where name in ('instant','hourly','daily'); + + insert into notification_types_del_methods + (type_id, delivery_method_id) + select v_foo, delivery_method_id + from notification_delivery_methods where short_name in ('email'); + + -- the notification type impl + impl_id := acs_sc_impl.new ( + impl_contract_name => 'NotificationType', + impl_name => 'forums_message_notif_type', + impl_pretty_name => 'forums_message_notif_type', + impl_owner_name => 'forums' + ); + + v_foo := acs_sc_impl.new_alias ( + 'NotificationType', + 'forums_message_notif_type', + 'GetURL', + 'forum::notification::get_url', + 'TCL' + ); + + v_foo := acs_sc_impl.new_alias ( + 'NotificationType', + 'forums_message_notif_type', + 'ProcessReply', + 'forum::notification::process_reply', + 'TCL' + ); + + acs_sc_binding.new ( + contract_name => 'NotificationType', + impl_name => 'forums_message_notif_type' + ); + + v_foo:= notification_type.new ( + short_name => 'forums_message_notif', + sc_impl_id => impl_id, + pretty_name => 'Message Notification', + description => 'Notifications for Message Thread', + creation_user => NULL, + creation_ip => NULL + ); + + -- enable the various intervals and delivery methods + insert into notification_types_intervals + (type_id, interval_id) + select v_foo, interval_id + from notification_intervals where name in ('instant','hourly','daily'); + + insert into notification_types_del_methods + (type_id, delivery_method_id) + select v_foo, delivery_method_id + from notification_delivery_methods where short_name in ('email'); + +end; +/ +show errors Index: openacs-4/contrib/packages/forums/sql/oracle/forums-notifications-sanitize.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-notifications-sanitize.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-notifications-sanitize.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,128 @@ +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert's UBB forums. Thanks Orchard Labs. +-- + +declare + v_foo integer; + v_impl_id integer; +begin + -- forums_forum + v_impl_id := acs_sc_impl.get_id ( + 'NotificationType', -- impl_contract_name + 'forums_forum_notif_type' -- impl_name + ); + + select type_id into v_foo from notification_types + where sc_impl_id = v_impl_id and short_name = 'forums_forum_notif'; + + delete from notification_types_intervals + where type_id = v_foo + and interval_id in ( + select interval_id + from notification_intervals + where name in ('instant','hourly','daily') + ); + + delete from notification_types_del_methods + where type_id = v_foo + and delivery_method_id in ( + select delivery_method_id + from notification_delivery_methods + where short_name in ('email') + ); + + for row in (select type_id + from notification_types + where short_name in ('forums_forum_notif')) + loop + notification_type.del(row.type_id); + end loop; + + acs_sc_binding.del( + contract_name => 'NotificationType', + impl_name => 'forums_forum_notif_type' + ); + + v_foo := acs_sc_impl.delete_alias( + 'NotificationType', + 'forums_forum_notif_type', + 'GetURL' + ); + + v_foo := acs_sc_impl.delete_alias( + 'NotificationType', + 'forums_forum_notif_type', + 'ProcessReply' + ); + + acs_sc_impl.del( + 'NotificationType', + 'forums_forum_notif_type' + ); + + -- forums_message + v_impl_id := acs_sc_impl.get_id ( + 'NotificationType', -- impl_contract_name + 'forums_message_notif_type' -- impl_name + ); + + select type_id into v_foo from notification_types + where sc_impl_id = v_impl_id and short_name = 'forums_message_notif'; + + delete from notification_types_intervals + where type_id = v_foo + and interval_id in ( + select interval_id + from notification_intervals + where name in ('instant','hourly','daily') + ); + + delete from notification_types_del_methods + where type_id = v_foo + and delivery_method_id in ( + select delivery_method_id + from notification_delivery_methods + where short_name in ('email') + ); + + for row in (select type_id + from notification_types + where short_name in ('forums_message_notif')) + loop + notification_type.del(row.type_id); + end loop; + + acs_sc_binding.del( + contract_name => 'NotificationType', + impl_name => 'forums_message_notif_type' + ); + + v_foo := acs_sc_impl.delete_alias( + 'NotificationType', + 'forums_message_notif_type', + 'GetURL' + ); + + v_foo := acs_sc_impl.delete_alias( + 'NotificationType', + 'forums_message_notif_type', + 'ProcessReply' + ); + + acs_sc_impl.del( + 'NotificationType', + 'forums_message_notif_type' + ); +end; +/ +show errors + + + + Index: openacs-4/contrib/packages/forums/sql/oracle/forums-search-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-search-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-search-create.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,273 @@ +-- +-- Copyright (C) 2001, 2002 MIT +-- +-- This file is part of dotLRN. +-- +-- dotLRN is free software; you can redistribute it and/or modify it under the +-- terms of the GNU General Public License as published by the Free Software +-- Foundation; either version 2 of the License, or (at your option) any later +-- version. +-- +-- dotLRN is distributed in the hope that it will be useful, but WITHOUT ANY +-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +-- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +-- details. +-- + +-- +-- Support for searching of forum messages +-- +-- @author yon@openforce.net +-- @creation-date 2002-07-01 +-- @version $Id: forums-search-create.sql,v 1.1 2007/01/23 13:24:04 hamiltonc Exp $ +-- + + + +-- Call this script like this: +-- +-- sqlplus /nolog @forums-search-create.sql +-- +-- &1 = ctxsys password +-- &2 = OpenACS database user +-- &3 = OpenACS database password + + +connect &2/&3; + +-- as normal user +create or replace procedure index_message ( + rid in rowid, + tlob in out NOCOPY clob +) +is + offset number := 1; +begin + + for row in (select forums_messages.subject, + forums_messages.content, + persons.first_names, + persons.last_name + from forums_messages, + persons + where forums_messages.rowid = rid + and forums_messages.user_id = persons.person_id) + loop + dbms_lob.writeappend(tlob, length(row.subject) + 1, ' ' || row.subject); + dbms_lob.append(tlob, row.content); + dbms_lob.writeappend(tlob, length(row.first_names) + 1, ' ' || row.first_names); + dbms_lob.writeappend(tlob, length(row.last_name) + 1, ' ' || row.last_name); + end loop; + +end; +/ +show errors + +-- as ctxsys +connect ctxsys/&1; + +create or replace procedure s_index_message ( + rid in rowid, + tlob in out NOCOPY clob +) +is +begin + &2..index_message(rid, tlob); +end; +/ +show errors + +grant execute on s_index_message to &2; +grant execute on ctx_ddl to &2; + +-- as normal user +connect &2/&3; + +execute ctx_ddl.create_preference('forums_user_datastore', 'user_datastore'); +execute ctx_ddl.set_attribute('forums_user_datastore', 'procedure', 's_index_message'); + +create index forums_content_idx + on forums_messages (content) + indextype is ctxsys.context + parameters ('datastore forums_user_datastore'); + +declare + v_job number; +begin + dbms_job.submit( + job => v_job, + what => 'ctxsys.ctx_ddl.sync_index(''forums_content_idx'');', + interval => 'sysdate + 1/24' + ); +end; +/ +show errors + +-- ripped off from site-wide-search + +-- if we pass in a very long string to im_convert, we will end up with internal +-- strings that are too long. Because this is relatively hard to debug, +-- we wrote im_convert_length_check to throw a more appropriate error message +-- Note that we raise an exception because passing such a long query to +-- interMedia is pretty slow. Alternative to the application error are to +-- 1. return the string as is +-- 2. increase the max length from 256 to 1024 +-- mbryzek@arsdigita.com, 7/6/2000 +create or replace procedure im_convert_length_check ( + p_string in varchar2, + p_number_chars_to_append in number, + p_max_length in number, + p_variable_name in varchar2 +) +is +begin + if nvl(length(p_string),0) + p_number_chars_to_append > p_max_length + then + raise_application_error(-20000, 'Variable "' || p_variable_name || '" exceeds ' || p_max_length || ' character declaration'); + end if; +end; +/ +show errors; + +-- this proc takes user supplied free text and transforms it into an interMedia +-- friendly query string. (provided by oracle). +create or replace function im_convert ( + query in varchar2 default null +) return varchar2 +is + i number := 0; + len number := 0; + char varchar2(1); + minusString varchar2(256) := ''; + plusString varchar2(256) := ''; + mainString varchar2(256) := ''; + mainAboutString varchar2(500) := ''; + finalString varchar2(500) := ''; + hasMain number := 0; + hasPlus number := 0; + hasMinus number := 0; + token varchar2(256); + tokenStart number := 1; + tokenFinish number := 0; + inPhrase number := 0; + inPlus number := 0; + inWord number := 0; + inMinus number := 0; + completePhrase number := 0; + completeWord number := 0; + code number := 0; +begin + + len := length(query); + + -- we iterate over the string to find special web operators + for i in 1..len loop + char := substr(query,i,1); + if(char = '"') then + if(inPhrase = 0) then + inPhrase := 1; + tokenStart := i; + else + inPhrase := 0; + completePhrase := 1; + tokenFinish := i-1; + end if; + elsif(char = ' ') then + if(inPhrase = 0) then + completeWord := 1; + tokenFinish := i-1; + end if; + elsif(char = '+') then + inPlus := 1; + tokenStart := i+1; + elsif((char = '-') and (i = tokenStart)) then + inMinus :=1; + tokenStart := i+1; + end if; + + if(completeWord=1) then + token := '{ '||substr(query,tokenStart,tokenFinish-tokenStart+1)||' }'; + if(inPlus=1) then + im_convert_length_check(plusString, 4+length(token), 256, 'plusString'); + plusString := plusString||','||token||'*10'; + hasPlus :=1; + elsif(inMinus=1) then + im_convert_length_check(minusString, 4+length(token), 256, 'minusString'); + minusString := minusString||'OR '||token||' '; + hasMinus :=1; + else + im_convert_length_check(mainString, 6+length(token), 256, 'mainString'); + mainString := mainString||' NEAR '||token; + im_convert_length_check(mainAboutString, 1+length(token), 500, 'mainAboutString'); + mainAboutString := mainAboutString||' '||token; + hasMain :=1; + end if; + tokenStart :=i+1; + tokenFinish :=0; + inPlus := 0; + inMinus :=0; + end if; + completePhrase := 0; + completeWord :=0; + end loop; + + -- find the last token + token := '{ '||substr(query,tokenStart,len-tokenStart+1)||' }'; + if(inPlus=1) then + im_convert_length_check(plusString, 4+length(token), 256, 'plusString'); + plusString := plusString||','||token||'*10'; + hasPlus :=1; + elsif(inMinus=1) then + im_convert_length_check(minusString, 4+length(token), 256, 'minusString'); + minusString := minusString||'OR '||token||' '; + hasMinus :=1; + else + im_convert_length_check(mainString, 6+length(token), 256, 'mainString'); + mainString := mainString||' NEAR '||token; + im_convert_length_check(mainAboutString, 1+length(token), 500, 'mainAboutString'); + mainAboutString := mainAboutString||' '||token; + hasMain :=1; + end if; + + mainString := substr(mainString,6,length(mainString)-5); + mainAboutString := replace(mainAboutString,'{',' '); + mainAboutString := replace(mainAboutString,'}',' '); + mainAboutString := replace(mainAboutString,')',' '); + mainAboutString := replace(mainAboutString,'(',' '); + plusString := substr(plusString,2,length(plusString)-1); + minusString := substr(minusString,4,length(minusString)-4); + + -- let's just check once for the length of finalString... note this uses the + -- longest possible string that is created in the rest of this function + im_convert_length_check(finalString, nvl(length(mainString),0) + nvl(length(mainAboutString),0) + nvl(length(minusString),0) + nvl(length(plusString),0) + 30, 500, 'finalString'); + + -- we find the components present and then process them based on the specific combinations + code := hasMain*4+hasPlus*2+hasMinus; + if(code = 7) then + finalString := '('||plusString||','||mainString||'*2.0,about('||mainAboutString||')*0.5) NOT ('||minusString||')'; + elsif (code = 6) then + finalString := plusString||','||mainString||'*2.0'||',about('||mainAboutString||')*0.5'; + elsif (code = 5) then + finalString := '('||mainString||',about('||mainAboutString||')) NOT ('||minusString||')'; + elsif (code = 4) then + finalString := mainString; + finalString := replace(finalString,'*1,',NULL); + finalString := '('||finalString||')*2.0,about('||mainAboutString||')'; + elsif (code = 3) then + finalString := '('||plusString||') NOT ('||minusString||')'; + elsif (code = 2) then + finalString := plusString; + elsif (code = 1) then + -- not is a binary operator for intermedia text + finalString := 'totallyImpossibleString'||' NOT ('||minusString||')'; + elsif (code = 0) then + finalString := ''; + end if; + + return finalString; +end; +/ +show errors; + +exit + Index: openacs-4/contrib/packages/forums/sql/oracle/forums-search-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-search-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-search-drop.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,66 @@ +-- +-- Copyright (C) 2001, 2002 MIT +-- +-- This file is part of dotLRN. +-- +-- dotLRN is free software; you can redistribute it and/or modify it under the +-- terms of the GNU General Public License as published by the Free Software +-- Foundation; either version 2 of the License, or (at your option) any later +-- version. +-- +-- dotLRN is distributed in the hope that it will be useful, but WITHOUT ANY +-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +-- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +-- details. +-- + +-- +-- Support for searching of forum messages +-- +-- @author yon@openforce.net +-- @creation-date 2002-07-01 +-- @version $Id: forums-search-drop.sql,v 1.1 2007/01/23 13:24:04 hamiltonc Exp $ +-- + +-- Call this script like this: +-- +-- sqlplus /nolog @forums-search-create.sql +-- +-- &1 = ctxsys password +-- &2 = OpenACS database user +-- &3 = OpenACS database password + + +connect &2/&3; + +drop function im_convert; +drop procedure im_convert_length_check; + +declare +begin + for row in (select job + from user_jobs + where what like '%&2..forums_content_idx%') + loop + dbms_job.remove(job => row.job); + end loop; +end; +/ +show errors + +drop index forums_content_idx; + +execute ctx_ddl.unset_attribute('forums_user_datastore', 'procedure'); +execute ctx_ddl.drop_preference('forums_user_datastore'); + +-- as ctxsys +connect ctxsys/&1; + +drop procedure s_index_message; + +-- as normal user +connect &2/&3; + +drop procedure index_message; + +exit Index: openacs-4/contrib/packages/forums/sql/oracle/forums-tree-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-tree-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-tree-create.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,59 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert. Thanks Orchard Labs! +-- + +-- +-- This is the sortkey code +-- + +create or replace trigger forums_mess_insert_tr +before insert on forums_messages +for each row +declare + v_max_child_sortkey forums_messages.max_child_sortkey%TYPE; + v_parent_sortkey forums_messages.tree_sortkey%TYPE; +begin + + if :new.parent_id is null + then + + select '', max_child_sortkey + into v_parent_sortkey, v_max_child_sortkey + from forums_forums + where forum_id = :new.forum_id + for update of max_child_sortkey; + + v_max_child_sortkey := tree.increment_key(v_max_child_sortkey); + + update forums_forums + set max_child_sortkey = v_max_child_sortkey + where forum_id = :new.forum_id; + + else + + select nvl(tree_sortkey, ''), max_child_sortkey + into v_parent_sortkey, v_max_child_sortkey + from forums_messages + where message_id = :new.parent_id + for update of max_child_sortkey; + + v_max_child_sortkey := tree.increment_key(v_max_child_sortkey); + + update forums_messages + set max_child_sortkey = v_max_child_sortkey + where message_id = :new.parent_id; + + end if; + + :new.tree_sortkey := v_parent_sortkey || v_max_child_sortkey; + +end forums_mess_insert_tr; +/ +show errors Index: openacs-4/contrib/packages/forums/sql/oracle/forums-tree-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/Attic/forums-tree-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/forums-tree-drop.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,12 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert. Thanks Orchard Labs! +-- + +drop trigger forums_mess_insert_tr; Index: openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-0.1d-0.2d.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/upgrade/Attic/upgrade-0.1d-0.2d.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-0.1d-0.2d.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,328 @@ +alter table forums_forums add (last_post date); +alter table forums_messages add (last_child_post date); + +declare + v_date date; +begin + + for row in (select forum_id + from forums_forums) + loop + + select last_modified into v_date + from acs_objects + where object_id = row.forum_id; + + update forums_forums + set last_post = v_date + where forum_id = row.forum_id; + + end loop; + + for row in (select message_id + from forums_messages + where parent_id is null) + loop + + -- forums 0.1d did not properly set the last_modified field of the object + -- row associated with the root message of a thread, so we need to calculate + -- it here. + + select max(o.last_modified) into v_date + from acs_objects o, forums_messages fm + where forums_message.root_message_id(fm.message_id) = row.message_id + and object_id = fm.message_id; + + update forums_messages + set last_child_post = v_date + where message_id = row.message_id; + + end loop; + +end; +/ +show errors; + +drop view forums_messages_approved; +create view forums_messages_approved +as + select * + from forums_messages + where state = 'approved'; + +drop view forums_messages_pending; +create view forums_messages_pending +as + select * + from forums_messages + where state= 'pending'; + +drop view forums_forums_enabled; +create view forums_forums_enabled +as + select * + from forums_forums + where enabled_p = 't'; + +create or replace package body forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + html_p in forums_messages.html_p%TYPE default 'f', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE + is + v_message_id acs_objects.object_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; + begin + + v_message_id := acs_object.new( + object_id => message_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => nvl(context_id, forum_id) + ); + + if state is null + then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id= new.forum_id; + + if v_forum_policy = 'moderated' then + v_state := 'pending'; + else + v_state := 'approved'; + end if; + else + v_state := state; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, html_p, user_id, posting_date, parent_id, state) + values + (v_message_id, forum_id, subject, content, html_p, user_id, posting_date, parent_id, v_state); + + -- DRB: Can't use root_message_id() here because it triggers a "mutating table" error + + select tree_sortkey into v_sortkey + from forums_messages + where message_id = v_message_id; + + update forums_forums + set last_post = posting_date + where forum_id = forums_message.new.forum_id; + + update forums_messages + set last_child_post = posting_date + where forum_id = forums_message.new.forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + + return v_message_id; + end new; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE + is + v_message_id forums_messages.message_id%TYPE; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = root_message_id.message_id; + + select message_id + into v_message_id + from forums_messages + where forum_id = v_forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + + return v_message_id; + end root_message_id; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_open.message_id; + + update forums_messages + set open_p = 't' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 't' + where message_id = thread_open.message_id; + end thread_open; + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_close.message_id; + + update forums_messages + set open_p = 'f' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 'f' + where message_id = thread_close.message_id; + end thread_close; + + procedure delete ( + message_id in forums_messages.message_id%TYPE + ) + is + begin + acs_object.delete(message_id); + end delete; + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_message forums_messages%ROWTYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = delete_thread.message_id; + + -- if it's already deleted + if SQL%NOTFOUND then + return; + end if; + + -- delete all children + -- order by tree_sortkey desc to guarantee + -- that we never delete a parent before its child + -- sortkeys are beautiful + for v_message in (select * + from forums_messages + where forum_id = v_forum_id + and tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + order by tree_sortkey desc) + loop + forums_message.delete(v_message.message_id); + end loop; + + -- delete the message itself + forums_message.delete(delete_thread.message_id); + end delete_thread; + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar + is + v_name forums_messages.subject%TYPE; + begin + select subject + into v_name + from forums_messages + where message_id = forums_message.name.message_id; + + return v_name; + end name; + +end forums_message; +/ +show errors + +create or replace package body forums_forum +as + + function new ( + forum_id in forums_forums.forum_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_forum', + name in forums_forums.name%TYPE, + charter in forums_forums.charter%TYPE default null, + presentation_type in forums_forums.presentation_type%TYPE, + posting_policy in forums_forums.posting_policy%TYPE, + package_id in forums_forums.package_id%TYPE, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_forums.forum_id%TYPE + is + v_forum_id forums_forums.forum_id%TYPE; + begin + v_forum_id := acs_object.new( + object_id => forum_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => nvl(context_id, package_id) + ); + + insert into forums_forums + (forum_id, name, charter, presentation_type, posting_policy, package_id) + values + (v_forum_id, name, charter, presentation_type, posting_policy, package_id); + + return v_forum_id; + end new; + + function name ( + forum_id in forums_forums.forum_id%TYPE + ) return varchar + is + v_name forums_forums.name%TYPE; + begin + select name + into v_name + from forums_forums + where forum_id = name.forum_id; + + return v_name; + end name; + + procedure delete ( + forum_id in forums_forums.forum_id%TYPE + ) + is + begin + acs_object.delete(forum_id); + end delete; + +end forums_forum; +/ +show errors Index: openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-0.2d-0.3d.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/upgrade/Attic/upgrade-0.2d-0.3d.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-0.2d-0.3d.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,6 @@ +-- forums/sql/oracle/upgrade-0.2d-0.3d.sql +-- +-- Changes for scalability davis@xarg.net + +create unique index forums_mess_forum_sk_un on forums_messages(forum_id, tree_sortkey); + Index: openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-0.3d-0.4d.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/upgrade/Attic/upgrade-0.3d-0.4d.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-0.3d-0.4d.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,3 @@ +-- Need these two for RI checks +create index forums_messages_user_id_idx ON forums_messages(user_id); +create index forums_messages_parent_id_idx ON forums_messages(parent_id); Index: openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.0.6-1.0.7d.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/upgrade/Attic/upgrade-1.0.6-1.0.7d.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.0.6-1.0.7d.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,492 @@ +alter table forums_forums add (thread_count integer default 0); +alter table forums_forums add (approved_thread_count integer default 0); + +alter table forums_messages add (reply_count integer default 0); +alter table forums_messages add (approved_reply_count integer default 0); + +create or replace view forums_forums_enabled +as + select * + from forums_forums + where enabled_p = 't'; + +create or replace view forums_messages_approved +as + select * + from forums_messages + where state = 'approved'; + +create or replace view forums_messages_pending +as + select * + from forums_messages + where state= 'pending'; + +update forums_forums +set approved_thread_count = (select count(message_id) + from forums_messages_approved fm + where fm.forum_id=forums_forums.forum_id + and fm.parent_id is null), + thread_count = (select count(message_id) + from forums_messages fm + where fm.forum_id=forums_forums.forum_id + and fm.parent_id is null); + +update forums_messages +set approved_reply_count = (select count(*) + from forums_messages_approved fm1 + where fm1.tree_sortkey + between tree.left(forums_messages.tree_sortkey) + and tree.right(forums_messages.tree_sortkey) + and forums_messages.forum_id = fm1.forum_id), + reply_count = (select count(*) + from forums_messages fm1 + where fm1.tree_sortkey + between tree.left(forums_messages.tree_sortkey) + and tree.right(forums_messages.tree_sortkey) + and forums_messages.forum_id = fm1.forum_id) +where parent_id is null; + +create or replace package forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + format in forums_messages.format%TYPE default 'text/plain', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ); + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ); + + procedure del ( + message_id in forums_messages.message_id%TYPE + ); + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ); + + procedure set_state( + message_id in forums_messages.message_id%TYPE, + state in forums_messages.state%TYPE + ); + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar; + +end forums_message; +/ +show errors + +create or replace package body forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + format in forums_messages.format%TYPE default 'text/plain', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE + is + v_message_id acs_objects.object_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; + begin + + v_message_id := acs_object.new( + object_id => message_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => nvl(context_id, forum_id) + ); + + if state is null + then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id= new.forum_id; + + if v_forum_policy = 'moderated' then + v_state := 'pending'; + else + v_state := 'approved'; + end if; + else + v_state := state; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, format, user_id, posting_date, last_child_post, parent_id, state) + values + (v_message_id, forum_id, subject, content, format, user_id, posting_date, posting_date, parent_id, v_state); + + select tree_sortkey into v_sortkey + from forums_messages + where message_id = v_message_id; + + update forums_forums + set last_post = forums_message.new.posting_date + where forum_id = forums_message.new.forum_id; + + -- DRB: Can't use root_message_id() here because it triggers a "mutating table" error + + if parent_id is null then + if v_state = 'approved' then + update forums_forums + set thread_count = thread_count + 1, + approved_thread_count = approved_thread_count + 1 + where forum_id = forums_message.new.forum_id; + else + update forums_forums + set thread_count = thread_count + 1 + where forum_id=forums_message.new.forum_id; + end if; + else + if v_state = 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count + 1, + reply_count = reply_count + 1, + last_child_post = sysdate + where forum_id = forums_message.new.forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + else + update forums_messages + set reply_count = reply_count + 1, + last_child_post = sysdate + where forum_id = forums_message.new.forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + end if; + end if; + + return v_message_id; + + end new; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE + is + v_message_id forums_messages.message_id%TYPE; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = root_message_id.message_id; + + select message_id + into v_message_id + from forums_messages + where forum_id = v_forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + + return v_message_id; + end root_message_id; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_open.message_id; + + update forums_messages + set open_p = 't' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 't' + where message_id = thread_open.message_id; + end thread_open; + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_close.message_id; + + update forums_messages + set open_p = 'f' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 'f' + where message_id = thread_close.message_id; + end thread_close; + + procedure del ( + message_id in forums_messages.message_id%TYPE + ) + is + v_cur forums_messages%ROWTYPE; + begin + + -- Maintain the forum thread counts + + select * into v_cur + from forums_messages + where message_id = forums_message.del.message_id; + + if v_cur.parent_id is null then + if v_cur.state = 'approved' then + update forums_forums + set thread_count = thread_count - 1, + approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + else + update forums_forums + set thread_count = thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + elsif v_cur.state = 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count - 1, + reply_count = reply_count - 1 + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + else + update forums_messages + set reply_count = reply_count - 1 + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + end if; + + acs_object.del(message_id); + + end del; + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_message forums_messages%ROWTYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = delete_thread.message_id; + + -- if it's already deleted + if SQL%NOTFOUND then + return; + end if; + + -- delete all children + -- order by tree_sortkey desc to guarantee + -- that we never delete a parent before its child + -- sortkeys are beautiful + for v_message in (select * + from forums_messages + where forum_id = v_forum_id + and tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + order by tree_sortkey desc) + loop + forums_message.del(v_message.message_id); + end loop; + + -- delete the message itself + forums_message.del(delete_thread.message_id); + end delete_thread; + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar + is + v_name forums_messages.subject%TYPE; + begin + select subject + into v_name + from forums_messages + where message_id = forums_message.name.message_id; + + return v_name; + end name; + + procedure set_state( + message_id in forums_messages.message_id%TYPE, + state in forums_messages.state%TYPE + ) + is + v_cur forums_messages%ROWTYPE; + begin + + select * into v_cur + from forums_messages + where message_id = forums_message.set_state.message_id; + + if v_cur.parent_id is null then + if state = 'approved' and v_cur.state <> 'approved' then + update forums_forums + set approved_thread_count = approved_thread_count + 1 + where forum_id=v_cur.forum_id; + elsif state <> 'approved' and v_cur.state = 'approved' then + update forums_forums + set approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + else + if state = 'approved' and v_cur.state <> 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count + 1 + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + elsif state <> 'approved' and v_cur.state = 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count - 1 + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + end if; + end if; + + update forums_messages + set state = forums_message.set_state.state + where message_id = forums_message.set_state.message_id; + + end set_state; + +end forums_message; +/ +show errors + +create or replace package forums_forum +as + + function new ( + forum_id in forums_forums.forum_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_forum', + name in forums_forums.name%TYPE, + charter in forums_forums.charter%TYPE default null, + presentation_type in forums_forums.presentation_type%TYPE, + posting_policy in forums_forums.posting_policy%TYPE, + package_id in forums_forums.package_id%TYPE, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_forums.forum_id%TYPE; + + function name ( + forum_id in forums_forums.forum_id%TYPE + ) return varchar; + + procedure del ( + forum_id in forums_forums.forum_id%TYPE + ); + +end forums_forum; +/ +show errors + +create or replace package body forums_forum +as + + function new ( + forum_id in forums_forums.forum_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_forum', + name in forums_forums.name%TYPE, + charter in forums_forums.charter%TYPE default null, + presentation_type in forums_forums.presentation_type%TYPE, + posting_policy in forums_forums.posting_policy%TYPE, + package_id in forums_forums.package_id%TYPE, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_forums.forum_id%TYPE + is + v_forum_id forums_forums.forum_id%TYPE; + begin + v_forum_id := acs_object.new( + object_id => forum_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => nvl(context_id, package_id) + ); + + insert into forums_forums + (forum_id, name, charter, presentation_type, posting_policy, package_id) + values + (v_forum_id, name, charter, presentation_type, posting_policy, package_id); + + return v_forum_id; + end new; + + function name ( + forum_id in forums_forums.forum_id%TYPE + ) return varchar + is + v_name forums_forums.name%TYPE; + begin + select name + into v_name + from forums_forums + where forum_id = name.forum_id; + + return v_name; + end name; + + procedure del ( + forum_id in forums_forums.forum_id%TYPE + ) + is + begin + acs_object.del(forum_id); + end del; + +end forums_forum; +/ +show errors Index: openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.0d2-1.0d3.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/upgrade/Attic/upgrade-1.0d2-1.0d3.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.0d2-1.0d3.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,260 @@ + +-- +-- Upgrade script for oracle 1.0d2 - 1.0d3 +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @creation-date 2003-10-3 +-- +-- The forums_message.new function updated the thread's last post date to the posting date +-- of the first post (!), because the code inadvertedly referred to the posting_date +-- column instead of the posting_date parameter. +-- + +create or replace package forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + html_p in forums_messages.html_p%TYPE default 'f', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ); + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ); + + procedure del ( + message_id in forums_messages.message_id%TYPE + ); + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ); + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar; + +end forums_message; +/ +show errors + +create or replace package body forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + html_p in forums_messages.html_p%TYPE default 'f', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE + is + v_message_id acs_objects.object_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; + begin + + v_message_id := acs_object.new( + object_id => message_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => nvl(context_id, forum_id) + ); + + if state is null + then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id= new.forum_id; + + if v_forum_policy = 'moderated' then + v_state := 'pending'; + else + v_state := 'approved'; + end if; + else + v_state := state; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, html_p, user_id, posting_date, parent_id, state) + values + (v_message_id, forum_id, subject, content, html_p, user_id, posting_date, parent_id, v_state); + + -- DRB: Can't use root_message_id() here because it triggers a "mutating table" error + + select tree_sortkey into v_sortkey + from forums_messages + where message_id = v_message_id; + + update forums_forums + set last_post = forums_message.new.posting_date + where forum_id = forums_message.new.forum_id; + + update forums_messages + set last_child_post = forums_message.new.posting_date + where forum_id = forums_message.new.forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + + return v_message_id; + end new; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE + is + v_message_id forums_messages.message_id%TYPE; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = root_message_id.message_id; + + select message_id + into v_message_id + from forums_messages + where forum_id = v_forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + + return v_message_id; + end root_message_id; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_open.message_id; + + update forums_messages + set open_p = 't' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 't' + where message_id = thread_open.message_id; + end thread_open; + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_close.message_id; + + update forums_messages + set open_p = 'f' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 'f' + where message_id = thread_close.message_id; + end thread_close; + + procedure del ( + message_id in forums_messages.message_id%TYPE + ) + is + begin + acs_object.del(message_id); + end del; + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_message forums_messages%ROWTYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = delete_thread.message_id; + + -- if it's already deleted + if SQL%NOTFOUND then + return; + end if; + + -- delete all children + -- order by tree_sortkey desc to guarantee + -- that we never delete a parent before its child + -- sortkeys are beautiful + for v_message in (select * + from forums_messages + where forum_id = v_forum_id + and tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + order by tree_sortkey desc) + loop + forums_message.del(v_message.message_id); + end loop; + + -- delete the message itself + forums_message.del(delete_thread.message_id); + end delete_thread; + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar + is + v_name forums_messages.subject%TYPE; + begin + select subject + into v_name + from forums_messages + where message_id = forums_message.name.message_id; + + return v_name; + end name; + +end forums_message; +/ +show errors Index: openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.0d3-1.0d4.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/upgrade/Attic/upgrade-1.0d3-1.0d4.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.0d3-1.0d4.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,364 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- The Package +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs! +-- + +create or replace package forums_forum +as + + function new ( + forum_id in forums_forums.forum_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_forum', + name in forums_forums.name%TYPE, + charter in forums_forums.charter%TYPE default null, + presentation_type in forums_forums.presentation_type%TYPE, + posting_policy in forums_forums.posting_policy%TYPE, + package_id in forums_forums.package_id%TYPE, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_forums.forum_id%TYPE; + + function name ( + forum_id in forums_forums.forum_id%TYPE + ) return varchar; + + procedure del ( + forum_id in forums_forums.forum_id%TYPE + ); + +end forums_forum; +/ +show errors + +create or replace package body forums_forum +as + + function new ( + forum_id in forums_forums.forum_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_forum', + name in forums_forums.name%TYPE, + charter in forums_forums.charter%TYPE default null, + presentation_type in forums_forums.presentation_type%TYPE, + posting_policy in forums_forums.posting_policy%TYPE, + package_id in forums_forums.package_id%TYPE, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_forums.forum_id%TYPE + is + v_forum_id forums_forums.forum_id%TYPE; + begin + v_forum_id := acs_object.new( + object_id => forum_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => nvl(context_id, package_id) + ); + + insert into forums_forums + (forum_id, name, charter, presentation_type, posting_policy, package_id) + values + (v_forum_id, name, charter, presentation_type, posting_policy, package_id); + + return v_forum_id; + end new; + + function name ( + forum_id in forums_forums.forum_id%TYPE + ) return varchar + is + v_name forums_forums.name%TYPE; + begin + select name + into v_name + from forums_forums + where forum_id = name.forum_id; + + return v_name; + end name; + + procedure del ( + forum_id in forums_forums.forum_id%TYPE + ) + is + begin + acs_object.del(forum_id); + end del; + +end forums_forum; +/ +show errors + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- The Package for Messages +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs! +-- + +create or replace package forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + html_p in forums_messages.html_p%TYPE default 'f', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ); + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ); + + procedure del ( + message_id in forums_messages.message_id%TYPE + ); + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ); + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar; + +end forums_message; +/ +show errors + +create or replace package body forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + html_p in forums_messages.html_p%TYPE default 'f', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE + is + v_message_id acs_objects.object_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; + begin + + v_message_id := acs_object.new( + object_id => message_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => nvl(context_id, forum_id) + ); + + if state is null + then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id= new.forum_id; + + if v_forum_policy = 'moderated' then + v_state := 'pending'; + else + v_state := 'approved'; + end if; + else + v_state := state; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, html_p, user_id, posting_date, parent_id, state) + values + (v_message_id, forum_id, subject, content, html_p, user_id, posting_date, parent_id, v_state); + + -- DRB: Can't use root_message_id() here because it triggers a "mutating table" error + + select tree_sortkey into v_sortkey + from forums_messages + where message_id = v_message_id; + + update forums_forums + set last_post = posting_date + where forum_id = forums_message.new.forum_id; + + update forums_messages + set last_child_post = posting_date + where forum_id = forums_message.new.forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + + return v_message_id; + end new; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE + is + v_message_id forums_messages.message_id%TYPE; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = root_message_id.message_id; + + select message_id + into v_message_id + from forums_messages + where forum_id = v_forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + + return v_message_id; + end root_message_id; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_open.message_id; + + update forums_messages + set open_p = 't' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 't' + where message_id = thread_open.message_id; + end thread_open; + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_close.message_id; + + update forums_messages + set open_p = 'f' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 'f' + where message_id = thread_close.message_id; + end thread_close; + + procedure del ( + message_id in forums_messages.message_id%TYPE + ) + is + begin + acs_object.del(message_id); + end del; + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_message forums_messages%ROWTYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = delete_thread.message_id; + + -- if it's already deleted + if SQL%NOTFOUND then + return; + end if; + + -- delete all children + -- order by tree_sortkey desc to guarantee + -- that we never delete a parent before its child + -- sortkeys are beautiful + for v_message in (select * + from forums_messages + where forum_id = v_forum_id + and tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + order by tree_sortkey desc) + loop + forums_message.del(v_message.message_id); + end loop; + + -- delete the message itself + forums_message.del(delete_thread.message_id); + end delete_thread; + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar + is + v_name forums_messages.subject%TYPE; + begin + select subject + into v_name + from forums_messages + where message_id = forums_message.name.message_id; + + return v_name; + end name; + +end forums_message; +/ +show errors Index: openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.0d4-1.0.1d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/upgrade/Attic/upgrade-1.0d4-1.0.1d2.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.0d4-1.0.1d2.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,285 @@ +alter table forums_messages add format varchar2(30) default 'text/plain'; + +update forums_messages +set format = 'text/html' +where html_p = 't'; +update forums_messages +set format = 'text/plain' +where html_p = 'f'; + +alter table forums_messages add constraint forums_mess_format_ck check (format in ('text/enhanced', 'text/plain', 'text/fixed-width', 'text/html')); +alter table forums_messages drop column html_p; + +-- forums-messages-package-create.sql +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- The Package for Messages +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs! +-- + +create or replace package forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + format in forums_messages.format%TYPE default 'text/plain', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ); + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ); + + procedure del ( + message_id in forums_messages.message_id%TYPE + ); + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ); + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar; + +end forums_message; +/ +show errors + +create or replace package body forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + format in forums_messages.format%TYPE default 'text/plain', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE + is + v_message_id acs_objects.object_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; + begin + + v_message_id := acs_object.new( + object_id => message_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => nvl(context_id, forum_id) + ); + + if state is null + then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id= new.forum_id; + + if v_forum_policy = 'moderated' then + v_state := 'pending'; + else + v_state := 'approved'; + end if; + else + v_state := state; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, format, user_id, posting_date, parent_id, state) + values + (v_message_id, forum_id, subject, content, format, user_id, posting_date, parent_id, v_state); + + -- DRB: Can't use root_message_id() here because it triggers a "mutating table" error + + select tree_sortkey into v_sortkey + from forums_messages + where message_id = v_message_id; + + update forums_forums + set last_post = forums_message.new.posting_date + where forum_id = forums_message.new.forum_id; + + update forums_messages + set last_child_post = forums_message.new.posting_date + where forum_id = forums_message.new.forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + + return v_message_id; + end new; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE + is + v_message_id forums_messages.message_id%TYPE; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = root_message_id.message_id; + + select message_id + into v_message_id + from forums_messages + where forum_id = v_forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + + return v_message_id; + end root_message_id; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_open.message_id; + + update forums_messages + set open_p = 't' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 't' + where message_id = thread_open.message_id; + end thread_open; + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_close.message_id; + + update forums_messages + set open_p = 'f' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 'f' + where message_id = thread_close.message_id; + end thread_close; + + procedure del ( + message_id in forums_messages.message_id%TYPE + ) + is + begin + acs_object.del(message_id); + end del; + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_message forums_messages%ROWTYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = delete_thread.message_id; + + -- if it's already deleted + if SQL%NOTFOUND then + return; + end if; + + -- delete all children + -- order by tree_sortkey desc to guarantee + -- that we never delete a parent before its child + -- sortkeys are beautiful + for v_message in (select * + from forums_messages + where forum_id = v_forum_id + and tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + order by tree_sortkey desc) + loop + forums_message.del(v_message.message_id); + end loop; + + -- delete the message itself + forums_message.del(delete_thread.message_id); + end delete_thread; + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar + is + v_name forums_messages.subject%TYPE; + begin + select subject + into v_name + from forums_messages + where message_id = forums_message.name.message_id; + + return v_name; + end name; + +end forums_message; +/ +show errors + + +create or replace view forums_messages_approved as + select * + from forums_messages + where state = 'approved'; + +create or replace view forums_messages_pending as + select * + from forums_messages + where state = 'pending'; + Index: openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.1.1-1.1.2d1.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/upgrade/Attic/upgrade-1.1.1-1.1.2d1.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.1.1-1.1.2d1.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,35 @@ +update acs_permissions + set privilege = 'read' + where privilege = 'forum_read' + and not exists (select 1 + from acs_permissions p1 + where p1.object_id = acs_permissions.object_id + and p1.grantee_id = acs_permissions.grantee_id + and p1.privilege = 'read'); + +delete from acs_permissions + where privilege = 'forum_read'; + +update acs_permissions + set privilege = 'write' + where privilege = 'forum_write' + and not exists (select 1 + from acs_permissions p1 + where p1.object_id = acs_permissions.object_id + and p1.grantee_id = acs_permissions.grantee_id + and p1.privilege = 'write'); + +delete from acs_permissions + where privilege = 'forum_write'; + +update acs_permissions + set privilege = 'create' + where privilege = 'forum_create' + and not exists (select 1 + from acs_permissions p1 + where p1.object_id = acs_permissions.object_id + and p1.grantee_id = acs_permissions.grantee_id + and p1.privilege = 'create'); + +delete from acs_permissions + where privilege = 'forum_create'; Index: openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.1.2d4-1.1.2d5.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/upgrade/Attic/upgrade-1.1.2d4-1.1.2d5.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.1.2d4-1.1.2d5.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,48 @@ +-- +-- Most of the forum_* privileges are now deprecated. A notable exception is +-- forum_moderate, which is little used but provides a way to grant moderation +-- privileges without granting full admin privileges. +-- +-- This script, plus accompanying changes in other parts of this package, +-- finishes that job started in upgrade-1.1.1-1.1.2d1.sql. +-- + +update acs_permissions +set privilege = 'read' +where privilege = 'forum_read'; + +update acs_permissions +set privilege = 'write' +where privilege = 'forum_write'; + +update acs_permissions +set privilege = 'create' +where privilege = 'forum_create'; + +update acs_permissions +set privilege = 'delete' +where privilege = 'forum_delete'; + +-- As best as we can tell this is never used even though it's granted +-- by dotlrn-forums. + +delete from acs_permissions where privilege = 'forum_post'; + +begin + acs_privilege.remove_child('read','forum_read'); + acs_privilege.remove_child('create','forum_create'); + acs_privilege.remove_child('write','forum_write'); + acs_privilege.remove_child('delete','forum_delete'); + acs_privilege.remove_child('forum_moderate','forum_read'); + acs_privilege.remove_child('forum_moderate','forum_post'); + acs_privilege.remove_child('forum_write','forum_read'); + acs_privilege.remove_child('forum_write','forum_post'); + + acs_privilege.drop_privilege('forum_read'); + acs_privilege.drop_privilege('forum_create'); + acs_privilege.drop_privilege('forum_write'); + acs_privilege.drop_privilege('forum_post'); + acs_privilege.drop_privilege('forum_delete'); +end; +/ +show errors; Index: openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.1d1-1.1d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/upgrade/Attic/upgrade-1.1d1-1.1d2.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.1d1-1.1d2.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,2 @@ +@@ ../forums-messages-package-create.sql +@@ ../forums-forums-package-create.sql Index: openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.2d1-1.2d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/oracle/upgrade/Attic/upgrade-1.2d1-1.2d2.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/oracle/upgrade/upgrade-1.2d1-1.2d2.sql 23 Jan 2007 13:24:04 -0000 1.1 @@ -0,0 +1,408 @@ +-- @author Jeff Davis davis@xarg.net +-- +-- bug 1807 last_poster rather than first poster should be shown in forums index page +-- add a last_poster to support this and update triggers to support it. + +alter table forums_messages add last_poster integer + constraint forums_mess_last_poster_fk + references users(user_id); + +-- Now populate the new column +update forums_messages +set last_poster = (select fm1.user_id +from forums_messages fm1 +where fm1.message_id = (select max(fm2.message_id) + from forums_messages fm2 + connect by prior fm2.message_id=fm2.parent_id + start with fm2.message_id = forums_messages.message_id)) +where forums_messages.parent_id is null; + +create or replace view forums_messages_approved +as + select * + from forums_messages + where state = 'approved'; + +create or replace view forums_messages_pending +as + select * + from forums_messages + where state= 'pending'; + + + +-- +-- Replace the procs which manipulate state and new message to save last_poster. +-- + +create or replace package forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + format in forums_messages.format%TYPE default 'text/plain', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ); + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ); + + procedure del ( + message_id in forums_messages.message_id%TYPE + ); + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ); + + procedure set_state( + message_id in forums_messages.message_id%TYPE, + state in forums_messages.state%TYPE + ); + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar; + +end forums_message; +/ +show errors + +create or replace package body forums_message +as + + function new ( + message_id in forums_messages.message_id%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'forums_message', + forum_id in forums_messages.forum_id%TYPE, + subject in forums_messages.subject%TYPE, + content in varchar, + format in forums_messages.format%TYPE default 'text/plain', + user_id in forums_messages.user_id%TYPE, + posting_date in forums_messages.posting_date%TYPE default sysdate, + state in forums_messages.state%TYPE default null, + parent_id in forums_messages.parent_id%TYPE default null, + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE, + context_id in acs_objects.context_id%TYPE default null + ) return forums_messages.message_id%TYPE + is + v_message_id acs_objects.object_id%TYPE; + v_package_id acs_objects.package_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; + begin + select package_id into v_package_id from forums_forums where forum_id = new.forum_id; + + v_message_id := acs_object.new( + object_id => message_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => nvl(context_id, forum_id), + title => subject, + package_id => v_package_id + ); + + if state is null + then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id= new.forum_id; + + if v_forum_policy = 'moderated' then + v_state := 'pending'; + else + v_state := 'approved'; + end if; + else + v_state := state; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, format, user_id, posting_date, last_child_post, parent_id, state, last_poster) + values + (v_message_id, forum_id, subject, content, format, user_id, posting_date, posting_date, parent_id, v_state, user_id); + + select tree_sortkey into v_sortkey + from forums_messages + where message_id = v_message_id; + + update forums_forums + set last_post = forums_message.new.posting_date + where forum_id = forums_message.new.forum_id; + + -- DRB: Can't use root_message_id() here because it triggers a "mutating table" error + + if parent_id is null then + if v_state = 'approved' then + update forums_forums + set thread_count = thread_count + 1, + approved_thread_count = approved_thread_count + 1 + where forum_id = forums_message.new.forum_id; + else + update forums_forums + set thread_count = thread_count + 1 + where forum_id=forums_message.new.forum_id; + end if; + else + if v_state = 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count + 1, + reply_count = reply_count + 1, + last_poster = forums_message.new.user_id, + last_child_post = forums_message.new.posting_date + where forum_id = forums_message.new.forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + else + update forums_messages + set reply_count = reply_count + 1 + where forum_id = forums_message.new.forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + end if; + end if; + + return v_message_id; + + end new; + + function root_message_id ( + message_id in forums_messages.message_id%TYPE + ) return forums_messages.message_id%TYPE + is + v_message_id forums_messages.message_id%TYPE; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = root_message_id.message_id; + + select message_id + into v_message_id + from forums_messages + where forum_id = v_forum_id + and tree_sortkey = tree.ancestor_key(v_sortkey, 1); + + return v_message_id; + end root_message_id; + + procedure thread_open ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_open.message_id; + + update forums_messages + set open_p = 't' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 't' + where message_id = thread_open.message_id; + end thread_open; + + procedure thread_close ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = thread_close.message_id; + + update forums_messages + set open_p = 'f' + where tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = 'f' + where message_id = thread_close.message_id; + end thread_close; + + procedure del ( + message_id in forums_messages.message_id%TYPE + ) + is + v_cur forums_messages%ROWTYPE; + begin + + -- Maintain the forum thread counts + + select * into v_cur + from forums_messages + where message_id = forums_message.del.message_id; + + if v_cur.parent_id is null then + if v_cur.state = 'approved' then + update forums_forums + set thread_count = thread_count - 1, + approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + else + update forums_forums + set thread_count = thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + elsif v_cur.state = 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count - 1, + reply_count = reply_count - 1 + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + else + update forums_messages + set reply_count = reply_count - 1 + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + end if; + + acs_object.del(message_id); + + end del; + + procedure delete_thread ( + message_id in forums_messages.message_id%TYPE + ) + is + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_message forums_messages%ROWTYPE; + begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = delete_thread.message_id; + + -- if it's already deleted + if SQL%NOTFOUND then + return; + end if; + + -- delete all children + -- order by tree_sortkey desc to guarantee + -- that we never delete a parent before its child + -- sortkeys are beautiful + for v_message in (select * + from forums_messages + where forum_id = v_forum_id + and tree_sortkey between tree.left(v_sortkey) and tree.right(v_sortkey) + order by tree_sortkey desc) + loop + forums_message.del(v_message.message_id); + end loop; + + -- delete the message itself + forums_message.del(delete_thread.message_id); + end delete_thread; + + function name ( + message_id in forums_messages.message_id%TYPE + ) return varchar + is + v_name forums_messages.subject%TYPE; + begin + select subject + into v_name + from forums_messages + where message_id = forums_message.name.message_id; + + return v_name; + end name; + + procedure set_state( + message_id in forums_messages.message_id%TYPE, + state in forums_messages.state%TYPE + ) + is + v_cur forums_messages%ROWTYPE; + v_last_child_post forums_messages.last_child_post%TYPE; + begin + + select * into v_cur + from forums_messages + where message_id = forums_message.set_state.message_id; + + if v_cur.parent_id is null then + if state = 'approved' and v_cur.state <> 'approved' then + update forums_forums + set approved_thread_count = approved_thread_count + 1 + where forum_id=v_cur.forum_id; + elsif state <> 'approved' and v_cur.state = 'approved' then + update forums_forums + set approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + else + if state = 'approved' and v_cur.state <> 'approved' then + select last_child_post into v_last_child_post + from forums_messages + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + if v_cur.posting_date > v_last_child_post then + update forums_messages + set approved_reply_count = approved_reply_count + 1, + last_poster = v_cur.user_id, + last_child_post = v_cur.posting_date + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + else + update forums_messages + set approved_reply_count = approved_reply_count + 1 + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + end if; + elsif state <> 'approved' and v_cur.state = 'approved' then + update forums_messages + set approved_reply_count = approved_reply_count - 1 + where forum_id = v_cur.forum_id + and tree_sortkey = tree.ancestor_key(v_cur.tree_sortkey, 1); + end if; + end if; + + update forums_messages + set state = forums_message.set_state.state + where message_id = forums_message.set_state.message_id; + + end set_state; + +end forums_message; +/ +show errors + Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-create.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,27 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert's UBB forums. Thanks Orchard Labs. +-- + +-- The basic forum constructs +\i forums-forums-create.sql +\i forums-forums-package-create.sql + +-- The messages +\i forums-messages-create.sql +\i forums-messages-package-create.sql + +-- tree stuff +\i forums-tree-create.sql + +-- notifications +\i forums-notifications-init.sql + +-- Search +\i forums-sc-create.sql Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-drop.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,26 @@ +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert's UBB forums. Thanks Orchard Labs. +-- + +-- Search +\i forums-sc-drop.sql + +-- notifications +\i forums-notifications-sanitize.sql + +-- tree stuff +\i forums-tree-drop.sql + +-- the messages +\i forums-messages-package-drop.sql +\i forums-messages-drop.sql + +-- The basic forum constructs +\i forums-forums-package-drop.sql +\i forums-forums-drop.sql Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-forums-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-forums-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-forums-create.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,101 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs. +-- + +-- privileges +begin; + -- The standard privilege 'admin' on a package allows a user to + -- create forums (enforced by URL). + -- The standard privilege 'create' on a forum allows a user to + -- create new threads. + -- The standard privilege 'write' on a message allows a user to + -- post a follow up message. + + -- forum_moderate lets us grant moderation without granting full admin + select acs_privilege__create_privilege('forum_moderate',null,null); + select acs_privilege__add_child('admin','forum_moderate'); + select acs_privilege__add_child('forum_moderate','create'); + select acs_privilege__add_child('forum_moderate','delete'); + select acs_privilege__add_child('forum_moderate','read'); + select acs_privilege__add_child('forum_moderate','write'); + + --return null; +end; + +create table forums_forums ( + forum_id integer + constraint forums_forum_id_nn + not null + constraint forums_forum_id_fk + references acs_objects (object_id) + constraint forums_forum_id_pk + primary key, + name varchar(200) + constraint forums_name_nn + not null, + charter varchar(4000), + presentation_type varchar(100) + constraint forums_presentation_type_nn + not null + constraint forums_presentation_type_ck + check (presentation_type in ('flat','threaded')), + posting_policy varchar(100) + constraint forums_posting_policy_nn + not null + constraint forums_posting_policy_ck + check (posting_policy in ('open','moderated','closed')), + max_child_sortkey varbit, + enabled_p char(1) + default 't' + constraint forums_enabled_p_nn + not null + constraint forums_enabled_p_ck + check (enabled_p in ('t','f')), + package_id integer + constraint forums_package_id_nn + not null, + thread_count integer default 0, + approved_thread_count integer default 0, + forums_forums integer default 0, + last_post timestamptz +); + +CREATE INDEX forums_forums_pkg_enable_idx + ON forums_forums + USING btree + (package_id, enabled_p); + +create view forums_forums_enabled +as + select * + from forums_forums + where enabled_p = 't'; + +create function inline_0 () +returns integer as' +begin + perform acs_object_type__create_type( + ''forums_forum'', + ''Forums Forum'', + ''Forums Forums'', + ''acs_object'', + ''forums_forums'', + ''forum_id'', + ''forums_forum'', + ''f'', + null, + ''forums_forum__name'' + ); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-forums-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-forums-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-forums-drop.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,49 @@ +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs. +-- + +-- privileges + +create function inline_0 () +returns integer as ' +begin + + delete from acs_permissions where privilege in (''forum_moderate''); + + -- remove children + perform acs_privilege__remove_child(''admin'',''forum_moderate''); + perform acs_privilege__remove_child(''forum_moderate'',''create''); + perform acs_privilege__remove_child(''forum_moderate'',''delete''); + perform acs_privilege__remove_child(''forum_moderate'',''read''); + perform acs_privilege__remove_child(''forum_moderate'',''write''); + + perform acs_privilege__drop_privilege(''forum_moderate''); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0 (); + +DROP INDEX forums_forums_pkg_enable_idx; +drop view forums_forums_enabled; +drop table forums_forums; + +create function inline_0 () +returns integer as ' +begin + perform acs_object_type__drop_type ( + ''forums_forum'', ''f'' + ); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0 (); Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-forums-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-forums-package-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-forums-package-create.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,74 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- The Package +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs! +-- + +select define_function_args('forums_forum__new','forum_id,object_type;forums_forum,name,charter,presentation_type,posting_policy,package_id,creation_date,creation_user,creation_ip,context_id'); + +create or replace function forums_forum__new (integer,varchar,varchar,varchar,varchar,varchar,integer,timestamptz,integer,varchar,integer) +returns integer as ' +declare + p_forum_id alias for $1; + p_object_type alias for $2; + p_name alias for $3; + p_charter alias for $4; + p_presentation_type alias for $5; + p_posting_policy alias for $6; + p_package_id alias for $7; + p_creation_date alias for $8; + p_creation_user alias for $9; + p_creation_ip alias for $10; + p_context_id alias for $11; + v_forum_id integer; +begin + v_forum_id:= acs_object__new( + p_forum_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + coalesce(p_context_id, p_package_id), + ''t'', + p_name, + p_package_id + ); + + insert into forums_forums + (forum_id, name, charter, presentation_type, posting_policy, package_id) + values + (v_forum_id, p_name, p_charter, p_presentation_type, p_posting_policy, p_package_id); + + return v_forum_id; +end; +' language 'plpgsql'; + +select define_function_args('forums_forum__name','forum_id'); + +create or replace function forums_forum__name(integer) +returns varchar as ' +declare + p_forum_id alias for $1; +begin + return name from forums_forums where forum_id = p_forum_id; +end; +' language 'plpgsql'; + +select define_function_args('forums_forum__delete','forum_id'); + +create or replace function forums_forum__delete(integer) +returns integer as ' +declare + p_forum_id alias for $1; +begin + perform acs_object__delete(p_forum_id); + return 0; +end; +' language 'plpgsql'; Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-forums-package-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-forums-package-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-forums-package-drop.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,18 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- The Package +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs! +-- + +drop function forums_forum__new (integer,varchar,varchar,varchar,varchar,varchar,integer,timestamptz,integer,varchar,integer); + +drop function forums_forum__name(integer); + +drop function forums_forum__delete(integer); Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-messages-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-messages-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-messages-create.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,102 @@ +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert. Thanks Orchard Labs! +-- + +create table forums_messages ( + message_id integer + constraint forums_message_id_fk + references acs_objects (object_id) + constraint forums_messages_pk + primary key, + forum_id integer + constraint forums_mess_forum_id_fk + references forums_forums (forum_id), + subject varchar(200), + content text, + user_id integer + constraint forums_mess_user_id_fk + references users(user_id) + constraint forums_mess_user_id_nn + not null, + posting_date timestamptz + default current_timestamp + constraint forum_mess_post_date_nn + not null, + state varchar(100) + constraint forum_mess_state_ck + check (state in ('pending','approved','rejected')), + format varchar(30) + default 'text/plain', + -- Hierarchy of messages + parent_id integer + constraint forum_mess_parent_id_fk + references forums_messages (message_id), + open_p char(1) + default 't' + constraint forum_mess_open_p_nn + not null + constraint forum_mess_open_p_ck + check (open_p in ('t','f')), + tree_sortkey varbit, + max_child_sortkey varbit, + last_child_post timestamptz, + reply_count integer + constraint forums_mess_reply_count_ck + check (reply_count >= 0) default 0, + approved_reply_count integer + constraint forums_mess_app_rep_count_ck + check (approved_reply_count >= 0) default 0, + last_poster integer + constraint forums_mess_last_poster_fk + references users(user_id), + constraint forums_mess_sk_forum_un + unique (tree_sortkey, forum_id) +); + +-- We do a some big queries on forum_id (thread count on index.tcl) so create a second index +-- ordered so it's useful for them +create unique index forums_mess_forum_sk_un on forums_messages(forum_id, tree_sortkey); +-- Need these two for RI checks +create index forums_messages_user_id_idx on forums_messages(user_id); +create index forums_messages_parent_id_idx on forums_messages(parent_id); +create index forum_messages_date_idx on forums_messages (forum_id, posting_date); + +create or replace view forums_messages_approved +as + select * + from forums_messages + where state = 'approved'; + +create or replace view forums_messages_pending +as + select * + from forums_messages + where state= 'pending'; + +create or replace function inline_0 () +returns integer as ' +begin + perform acs_object_type__create_type( + ''forums_message'', + ''Forums Message'', + ''Forums Messages'', + ''acs_object'', + ''forums_messages'', + ''message_id'', + ''forums_message'', + ''f'', + null, + ''forums_message__name'' + ); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0 (); Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-messages-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-messages-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-messages-drop.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,26 @@ +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert. Thanks Orchard Labs! +-- + +drop view forums_messages_pending; +drop view forums_messages_approved; +drop table forums_messages; + +create function inline_0 () +returns integer as ' +begin + perform acs_object_type__drop_type ( + ''forums_message'', ''f'' + ); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0 (); Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-messages-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-messages-package-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-messages-package-create.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,330 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- @cvs-id $Id: forums-messages-package-create.sql,v 1.1 2007/01/23 13:24:05 hamiltonc Exp $ +-- +-- The Package for Messages +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs! +-- + +select define_function_args ('forums_message__new', 'message_id,object_type;forums_message,forum_id,subject,content,format,user_id,state,parent_id,creation_date,creation_user,creation_ip,context_id'); + +-- Get rid of the old version so we'll throw an error if the admin forgets to reboot +-- OpenACS after the upgrade (package_instantiate_object caches param lists) +create or replace function forums_message__new (integer,varchar,integer,varchar,text,char,integer,varchar,integer,timestamptz,integer,varchar,integer) +returns integer as ' +declare + p_message_id alias for $1; + p_object_type alias for $2; + p_forum_id alias for $3; + p_subject alias for $4; + p_content alias for $5; + p_format alias for $6; + p_user_id alias for $7; + p_state alias for $8; + p_parent_id alias for $9; + p_creation_date alias for $10; + p_creation_user alias for $11; + p_creation_ip alias for $12; + p_context_id alias for $13; + v_message_id integer; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; + v_posting_date forums_messages.posting_date%TYPE; + v_package_id acs_objects.package_id%TYPE; +begin + + select package_id into v_package_id from forums_forums where forum_id = p_forum_id; + + if v_package_id is null then + raise exception ''forums_message__new: forum_id % not found'', p_forum_id; + end if; + + v_message_id := acs_object__new( + p_message_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + coalesce(p_context_id, p_forum_id), + ''t'', + p_subject, + v_package_id + ); + + if p_state is null then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id = p_forum_id; + + if v_forum_policy = ''moderated'' + then v_state := ''pending''; + else v_state := ''approved''; + end if; + else + v_state := p_state; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, format, user_id, parent_id, state, last_child_post, last_poster) + values + (v_message_id, p_forum_id, p_subject, p_content, p_format, p_user_id, p_parent_id, + v_state, current_timestamp, p_user_id); + + update forums_forums + set last_post = current_timestamp + where forum_id = p_forum_id; + + if p_parent_id is null then + if v_state = ''approved'' then + update forums_forums + set thread_count = thread_count + 1, + approved_thread_count = approved_thread_count + 1 + where forum_id=p_forum_id; + else + update forums_forums + set thread_count = thread_count + 1 + where forum_id=p_forum_id; + end if; + else + if v_state = ''approved'' then + update forums_messages + set approved_reply_count = approved_reply_count + 1, + reply_count = reply_count + 1, + last_poster = p_user_id, + last_child_post = current_timestamp + where message_id = forums_message__root_message_id(v_message_id); + else + -- dont update last_poster, last_child_post when not approved + update forums_messages + set reply_count = reply_count + 1 + where message_id = forums_message__root_message_id(v_message_id); + end if; + end if; + + return v_message_id; + +end;' language 'plpgsql'; + +select define_function_args ('forums_message__root_message_id', 'message_id'); + +create or replace function forums_message__root_message_id (integer) +returns integer as ' +declare + p_message_id alias for $1; + v_message_id forums_messages.message_id%TYPE; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; +begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = p_message_id; + + select message_id + into v_message_id + from forums_messages + where forum_id = v_forum_id + and tree_sortkey = tree_ancestor_key(v_sortkey, 1); + + return v_message_id; +end; +' language 'plpgsql' stable strict; + +select define_function_args ('forums_message__thread_open', 'message_id'); + +create or replace function forums_message__thread_open (integer) +returns integer as ' +declare + p_message_id alias for $1; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; +begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = p_message_id; + + update forums_messages + set open_p = ''t'' + where tree_sortkey between tree_left(v_sortkey) and tree_right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = ''t'' + where message_id = p_message_id; + + return 0; +end; +' language 'plpgsql'; + +select define_function_args ('forums_message__thread_close', 'message_id'); + +create or replace function forums_message__thread_close (integer) +returns integer as ' +declare + p_message_id alias for $1; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; +begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = p_message_id; + + update forums_messages + set open_p = ''f'' + where tree_sortkey between tree_left(v_sortkey) and tree_right(v_sortkey) + and forum_id = v_forum_id; + + update forums_messages + set open_p = ''f'' + where message_id = p_message_id; + + return 0; +end; +' language 'plpgsql'; + +select define_function_args ('forums_message__set_state', 'message_id,state'); + +create or replace function forums_message__set_state(integer,varchar) returns integer as ' +declare + p_message_id alias for $1; + p_state alias for $2; + v_cur record; +begin + + select into v_cur * + from forums_messages + where message_id = p_message_id; + + if v_cur.parent_id is null then + if p_state = ''approved'' and v_cur.state <> ''approved'' then + update forums_forums + set approved_thread_count = approved_thread_count + 1 + where forum_id=v_cur.forum_id; + elsif p_state <> ''approved'' and v_cur.state = ''approved'' then + update forums_forums + set approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + else + if p_state = ''approved'' and v_cur.state <> ''approved'' then + update forums_messages + set approved_reply_count = approved_reply_count + 1, + last_poster = (case when v_cur.posting_date > last_child_post then v_cur.user_id else last_poster end), + last_child_post = (case when v_cur.posting_date > last_child_post then v_cur.posting_date else last_child_post end) + where message_id = forums_message__root_message_id(v_cur.message_id); + elsif p_state <> ''approved'' and v_cur.state = ''approved'' then + update forums_messages + set approved_reply_count = approved_reply_count - 1 + where message_id = forums_message__root_message_id(v_cur.message_id); + end if; + end if; + + update forums_messages + set state = p_state + where message_id = p_message_id; + + return 0; + +end;' language 'plpgsql'; + +select define_function_args ('forums_message__delete', 'message_id'); + +create or replace function forums_message__delete (integer) +returns integer as ' +declare + p_message_id alias for $1; + v_cur record; +begin + + -- Maintain the forum thread counts + + select into v_cur * + from forums_messages + where message_id = p_message_id; + + if v_cur.parent_id is null then + if v_cur.state = ''approved'' then + update forums_forums + set thread_count = thread_count - 1, + approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + else + update forums_forums + set thread_count = thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + elsif v_cur.state = ''approved'' then + update forums_messages + set approved_reply_count = approved_reply_count - 1, + reply_count = reply_count - 1 + where message_id = forums_message__root_message_id(v_cur.message_id); + else + update forums_messages + set reply_count = reply_count - 1 + where message_id = forums_message__root_message_id(v_cur.message_id); + end if; + + perform acs_object__delete(p_message_id); + return 0; +end;' language 'plpgsql'; + +select define_function_args ('forums_message__delete_thread', 'message_id'); + +create or replace function forums_message__delete_thread (integer) +returns integer as ' +declare + p_message_id alias for $1; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_message RECORD; +begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = p_message_id; + + -- if it is already deleted + if v_forum_id is null + then return 0; + end if; + + -- delete all children + -- order by tree_sortkey desc to guarantee + -- that we never delete a parent before its child + -- sortkeys are beautiful + for v_message in select * + from forums_messages + where forum_id = v_forum_id + and tree_sortkey between tree_left(v_sortkey) and tree_right(v_sortkey) + order by tree_sortkey desc + loop + -- Avoid the count bookkeeping down in forums_message__delete + perform forums_message__delete(v_message.message_id); + end loop; + + -- delete the message itself + perform forums_message__delete(p_message_id); + + return 0; +end;' language 'plpgsql'; + + +select define_function_args('forums_message__name','message_id'); + +create or replace function forums_message__name (integer) +returns varchar as ' +declare + p_message_id alias for $1; +begin + return subject from forums_messages where message_id = p_message_id; +end; +' language 'plpgsql'; Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-messages-package-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-messages-package-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-messages-package-drop.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,26 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- The Package for Messages +-- +-- This code is newly concocted by Ben, but with heavy concepts and heavy code +-- chunks lifted from Gilbert. Thanks Orchard Labs! +-- + +drop function forums_message__new (integer,varchar,integer,varchar,text,char,integer,varchar,integer,timestamptz,integer,varchar,integer); + +drop function forums_message__root_message_id (integer); + +drop function forums_message__thread_open (integer); + +drop function forums_message__thread_close (integer); + +drop function forums_message__delete (integer); + +drop function forums_message__delete_thread (integer); + +drop function forums_message__name (integer); Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-notifications-init.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-notifications-init.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-notifications-init.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,126 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert's UBB forums. Thanks Orchard Labs. +-- + +-- the integration with Notifications + +create function inline_0() returns integer as ' +declare + impl_id integer; + v_foo integer; +begin + -- the notification type impl + impl_id := acs_sc_impl__new ( + ''NotificationType'', + ''forums_forum_notif_type'', + ''forums'' + ); + + v_foo := acs_sc_impl_alias__new ( + ''NotificationType'', + ''forums_forum_notif_type'', + ''GetURL'', + ''forum::notification::get_url'', + ''TCL'' + ); + + v_foo := acs_sc_impl_alias__new ( + ''NotificationType'', + ''forums_forum_notif_type'', + ''ProcessReply'', + ''forum::notification::process_reply'', + ''TCL'' + ); + + PERFORM acs_sc_binding__new ( + ''NotificationType'', + ''forums_forum_notif_type'' + ); + + v_foo:= notification_type__new ( + NULL, + impl_id, + ''forums_forum_notif'', + ''Forum Notification'', + ''Notifications for Entire Forums'', + now(), + NULL, + NULL, + NULL + ); + + -- enable the various intervals and delivery methods + insert into notification_types_intervals + (type_id, interval_id) + select v_foo, interval_id + from notification_intervals where name in (''instant'',''hourly'',''daily''); + + insert into notification_types_del_methods + (type_id, delivery_method_id) + select v_foo, delivery_method_id + from notification_delivery_methods where short_name in (''email''); + + -- the notification type impl + impl_id := acs_sc_impl__new ( + ''NotificationType'', + ''forums_message_notif_type'', + ''forums'' + ); + + v_foo := acs_sc_impl_alias__new ( + ''NotificationType'', + ''forums_message_notif_type'', + ''GetURL'', + ''forum::notification::get_url'', + ''TCL'' + ); + + v_foo := acs_sc_impl_alias__new ( + ''NotificationType'', + ''forums_message_notif_type'', + ''ProcessReply'', + ''forum::notification::process_reply'', + ''TCL'' + ); + + PERFORM acs_sc_binding__new ( + ''NotificationType'', + ''forums_message_notif_type'' + ); + + v_foo:= notification_type__new ( + NULL, + impl_id, + ''forums_message_notif'', + ''Message Notification'', + ''Notifications for Message Thread'', + now(), + NULL, + NULL, + NULL + ); + + -- enable the various intervals and delivery methods + insert into notification_types_intervals + (type_id, interval_id) + select v_foo, interval_id + from notification_intervals where name in (''instant'',''hourly'',''daily''); + + insert into notification_types_del_methods + (type_id, delivery_method_id) + select v_foo, delivery_method_id + from notification_delivery_methods where short_name in (''email''); + + return (0); +end; +' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); \ No newline at end of file Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-notifications-sanitize.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-notifications-sanitize.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-notifications-sanitize.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,136 @@ +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert's UBB forums. Thanks Orchard Labs. +-- + +create function inline_0 () +returns integer as ' +declare + row record; +begin + for row in select nt.type_id + from notification_types nt + where nt.short_name in (''forums_forum_notif'', ''forums_message_notif'') + loop + perform notification_type__delete(row.type_id); + end loop; + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0 (); + +-- +-- Service contract drop stuff was missing - Roberto Mello +-- + +create function inline_0() returns integer as ' +declare + impl_id integer; + v_foo integer; +begin + + -- the notification type impl + impl_id := acs_sc_impl__get_id ( + ''NotificationType'', -- impl_contract_name + ''forums_forum_notif_type'' -- impl_name + ); + + PERFORM acs_sc_binding__delete ( + ''NotificationType'', + ''forums_forum_notif_type'' + ); + + v_foo := acs_sc_impl_alias__delete ( + ''NotificationType'', -- impl_contract_name + ''forums_forum_notif_type'', -- impl_name + ''GetURL'' -- impl_operation_name + ); + + v_foo := acs_sc_impl_alias__delete ( + ''NotificationType'', -- impl_contract_name + ''forums_forum_notif_type'', -- impl_name + ''ProcessReply'' -- impl_operation_name + ); + + select into v_foo type_id + from notification_types + where sc_impl_id = impl_id + and short_name = ''forums_forum_notif''; + + perform notification_type__delete (v_foo); + + delete from notification_types_intervals + where type_id = v_foo + and interval_id in ( + select interval_id + from notification_intervals + where name in (''instant'',''hourly'',''daily'') + ); + + delete from notification_types_del_methods + where type_id = v_foo + and delivery_method_id in ( + select delivery_method_id + from notification_delivery_methods + where short_name in (''email'') + ); + + -- the notification type impl + impl_id := acs_sc_impl__get_id ( + ''NotificationType'', + ''forums_message_notif_type'' + ); + + PERFORM acs_sc_binding__delete ( + ''NotificationType'', + ''forums_message_notif_type'' + ); + + v_foo := acs_sc_impl_alias__delete ( + ''NotificationType'', + ''forums_message_notif_type'', + ''GetURL'' + ); + + v_foo := acs_sc_impl_alias__delete ( + ''NotificationType'', + ''forums_message_notif_type'', + ''ProcessReply'' + ); + + select into v_foo type_id + from notification_types + where sc_impl_id = impl_id + and short_name = ''forums_message_notif''; + + perform notification_type__delete (v_foo); + + delete from notification_types_intervals + where type_id = v_foo + and interval_id in ( + select interval_id + from notification_intervals + where name in (''instant'',''hourly'',''daily'') + ); + + delete from notification_types_del_methods + where type_id = v_foo + and delivery_method_id in ( + select delivery_method_id + from notification_delivery_methods + where short_name in (''email'') + ); + + return (0); +end; +' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-sc-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-sc-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-sc-create.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,95 @@ +-- forums service contracts for Search package +-- dave bauer +-- August 7, 2002 + +-- jcd: 2004-04-01 moved the sc create to the tcl callbacks, and added one for forum_forum objtype +-- TODO-JCD: trigger for forums_forums + +-- til: only indexing full threads. changes to child messages will be treated as +-- change to the thread. + +create or replace function forums_message_search__itrg () +returns trigger as ' +begin + if new.parent_id is null then + perform search_observer__enqueue(new.message_id,''INSERT''); + else + perform search_observer__enqueue(forums_message__root_message_id(new.parent_id),''UPDATE''); + end if; + return new; +end;' language 'plpgsql'; + +create or replace function forums_message_search__dtrg () +returns trigger as ' +declare + v_root_message_id forums_messages.message_id%TYPE; +begin + -- if the deleted msg has a parent then its an UPDATE to a thread, otherwise a DELETE. + + if old.parent_id is null then + perform search_observer__enqueue(old.message_id,''DELETE''); + else + v_root_message_id := forums_message__root_message_id(old.parent_id); + if not v_root_message_id is null then + perform search_observer__enqueue(v_root_message_id,''UPDATE''); + end if; + end if; + + return old; +end;' language 'plpgsql'; + +create or replace function forums_message_search__utrg () +returns trigger as ' +begin + perform search_observer__enqueue(forums_message__root_message_id (old.message_id),''UPDATE''); + return old; +end;' language 'plpgsql'; + + +create trigger forums_message_search__itrg after insert on forums_messages +for each row execute procedure forums_message_search__itrg (); + +create trigger forums_message_search__dtrg after delete on forums_messages +for each row execute procedure forums_message_search__dtrg (); + +create trigger forums_message_search__utrg after update on forums_messages +for each row execute procedure forums_message_search__utrg (); + + + +-- forums_forums indexing trigger +create or replace function forums_forums_search__itrg () +returns trigger as ' +begin + perform search_observer__enqueue(new.forum_id,''INSERT''); + + return new; +end;' language 'plpgsql'; + +create or replace function forums_forums_search__utrg () +returns trigger as ' +begin + perform search_observer__enqueue(new.forum_id,''UPDATE''); + + return new; +end;' language 'plpgsql'; + +create or replace function forums_forums_search__dtrg () +returns trigger as ' +begin + perform search_observer__enqueue(old.forum_id,''DELETE''); + + return old; +end;' language 'plpgsql'; + + + +create trigger forums_forums_search__itrg after insert on forums_forums +for each row execute procedure forums_forums_search__itrg (); + +create trigger forums_forums_search__utrg after update on forums_forums +for each row execute procedure forums_forums_search__utrg (); + +create trigger forums_forums_search__dtrg after delete on forums_forums +for each row execute procedure forums_forums_search__dtrg (); + Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-sc-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-sc-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-sc-drop.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,24 @@ +-- /packages/news/sql/news-sc-drop.sql +-- +-- @author Robert Locke (rlocke@infiniteinfo.com) +-- @created 2001-10-23 +-- @cvs-id $Id: forums-sc-drop.sql,v 1.1 2007/01/23 13:24:05 hamiltonc Exp $ +-- +-- Removes search support from news module. +-- +drop trigger forums_message_search__itrg on forums_messages; +drop trigger forums_message_search__dtrg on forums_messages; +drop trigger forums_message_search__utrg on forums_messages; + +drop function forums_message_search__itrg (); +drop function forums_message_search__dtrg (); +drop function forums_message_search__utrg (); + +drop trigger forums_forums_search__itrg on forums_forums; +drop trigger forums_forums_search__dtrg on forums_forums; +drop trigger forums_forums_search__utrg on forums_forums; + +drop function forums_forums_search__itrg (); +drop function forums_forums_search__dtrg (); +drop function forums_forums_search__utrg (); + Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-tree-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-tree-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-tree-create.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,62 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert. Thanks Orchard Labs! +-- + +-- +-- This is the sortkey code +-- + +create function forums_mess_insert_tr () +returns opaque as ' +declare + v_max_child_sortkey forums_forums.max_child_sortkey%TYPE; + v_parent_sortkey forums_messages.tree_sortkey%TYPE; +begin + + if new.parent_id is null + then + + select '''', max_child_sortkey + into v_parent_sortkey, v_max_child_sortkey + from forums_forums + where forum_id = new.forum_id + for update; + + v_max_child_sortkey := tree_increment_key(v_max_child_sortkey); + + update forums_forums + set max_child_sortkey = v_max_child_sortkey + where forum_id = new.forum_id; + + else + + select coalesce(tree_sortkey, ''''), max_child_sortkey + into v_parent_sortkey, v_max_child_sortkey + from forums_messages + where message_id = new.parent_id + for update; + + v_max_child_sortkey := tree_increment_key(v_max_child_sortkey); + + update forums_messages + set max_child_sortkey = v_max_child_sortkey + where message_id = new.parent_id; + + end if; + + new.tree_sortkey := v_parent_sortkey || v_max_child_sortkey; + + return new; +end;' language 'plpgsql'; + +create trigger forums_mess_insert_tr +before insert on forums_messages +for each row +execute procedure forums_mess_insert_tr(); Index: openacs-4/contrib/packages/forums/sql/postgresql/forums-tree-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/Attic/forums-tree-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/forums-tree-drop.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,17 @@ + +-- +-- The Forums Package +-- +-- @author gwong@orchardlabs.com,ben@openforce.biz +-- @creation-date 2002-05-16 +-- +-- This code is newly concocted by Ben, but with significant concepts and code +-- lifted from Gilbert. Thanks Orchard Labs! +-- + +-- +-- This is the sortkey code +-- + +drop trigger forums_mess_insert_tr on forums_messages; +drop function forums_mess_insert_tr (); Index: openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-0.1d-0.2d.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/upgrade/Attic/upgrade-0.1d-0.2d.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-0.1d-0.2d.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,173 @@ +alter table forums_forums add column last_post timestamptz; +alter table forums_messages add column last_child_post timestamptz; + +create or replace function t () returns integer as ' +declare + v_record record; + v_timestamp timestamptz; +begin + + for v_record in select forum_id + from forums_forums + loop + + select last_modified into v_timestamp + from acs_objects + where object_id = v_record.forum_id; + + update forums_forums + set last_post = v_timestamp + where forum_id = v_record.forum_id; + + end loop; + + for v_record in select message_id + from forums_messages + where parent_id is null + loop + + -- forums 0.1d did not properly set the last_modified field of the object + -- row associated with the root message of a thread, so we need to calculate + -- it here. + + select max(o.last_modified) into v_timestamp + from acs_objects o, forums_messages fm + where forums_message__root_message_id(fm.message_id) = v_record.message_id + and object_id = fm.message_id; + + update forums_messages + set last_child_post = v_timestamp + where message_id = v_record.message_id; + + end loop; + + return 1; + +end;' language 'plpgsql'; + +select t(); + +drop view forums_messages_approved; +create view forums_messages_approved +as + select * + from forums_messages + where state = 'approved'; + +drop view forums_messages_pending; +create view forums_messages_pending +as + select * + from forums_messages + where state= 'pending'; + +drop view forums_forums_enabled; +create view forums_forums_enabled +as + select * + from forums_forums + where enabled_p = 't'; + +create or replace function forums_message__new (integer,varchar,integer,varchar,text,char,integer,timestamptz,varchar,integer,timestamptz,integer,varchar,integer) +returns integer as ' +declare + p_message_id alias for $1; + p_object_type alias for $2; + p_forum_id alias for $3; + p_subject alias for $4; + p_content alias for $5; + p_html_p alias for $6; + p_user_id alias for $7; + p_posting_date alias for $8; + p_state alias for $9; + p_parent_id alias for $10; + p_creation_date alias for $11; + p_creation_user alias for $12; + p_creation_ip alias for $13; + p_context_id alias for $14; + v_message_id integer; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; + v_posting_date forums_messages.posting_date%TYPE; +begin + v_message_id := acs_object__new( + p_message_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + coalesce(p_context_id, p_forum_id) + ); + + if p_state is null then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id = p_forum_id; + + if v_forum_policy = ''moderated'' + then v_state := ''pending''; + else v_state := ''approved''; + end if; + else + v_state := p_state; + end if; + + if p_posting_date is null then + v_posting_date = now(); + else + v_posting_date = p_posting_date; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, html_p, user_id, posting_date, parent_id, state) + values + (v_message_id, p_forum_id, p_subject, p_content, p_html_p, p_user_id, v_posting_date, p_parent_id, v_state); + + update forums_forums + set last_post = v_posting_date + where forum_id = p_forum_id; + + update forums_messages + set last_child_post = v_posting_date + where message_id = forums_message__root_message_id(v_message_id); + + return v_message_id; + +end; +' language 'plpgsql'; + +create or replace function forums_forum__new (integer,varchar,varchar,varchar,varchar,varchar,integer,timestamptz,integer,varchar,integer) +returns integer as ' +declare + p_forum_id alias for $1; + p_object_type alias for $2; + p_name alias for $3; + p_charter alias for $4; + p_presentation_type alias for $5; + p_posting_policy alias for $6; + p_package_id alias for $7; + p_creation_date alias for $8; + p_creation_user alias for $9; + p_creation_ip alias for $10; + p_context_id alias for $11; + v_forum_id integer; +begin + v_forum_id:= acs_object__new( + p_forum_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + coalesce(p_context_id, p_package_id) + ); + + insert into forums_forums + (forum_id, name, charter, presentation_type, posting_policy, package_id) + values + (v_forum_id, p_name, p_charter, p_presentation_type, p_posting_policy, p_package_id); + + return v_forum_id; +end; +' language 'plpgsql'; + Index: openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-0.2d-0.3d.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/upgrade/Attic/upgrade-0.2d-0.3d.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-0.2d-0.3d.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,28 @@ +-- forums/sql/postgresql/upgrade-0.2d-0.3d.sql +-- +-- Changes for scalability davis@xarg.net + +create unique index forums_mess_forum_sk_un on forums_messages(forum_id, tree_sortkey); + +create or replace function forums_message__root_message_id (integer) +returns integer as ' +declare + p_message_id alias for $1; + v_message_id forums_messages.message_id%TYPE; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; +begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = p_message_id; + + select message_id + into v_message_id + from forums_messages + where forum_id = v_forum_id + and tree_sortkey = tree_ancestor_key(v_sortkey, 1); + + return v_message_id; +end; +' language 'plpgsql' with(isstrict,iscachable); Index: openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-0.3d-0.4d.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/upgrade/Attic/upgrade-0.3d-0.4d.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-0.3d-0.4d.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,3 @@ +-- Need these two for RI checks +create index forums_messages_user_id_idx ON forums_messages(user_id); +create index forums_messages_parent_id_idx ON forums_messages(parent_id); Index: openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.0.6-1.0.7d.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/upgrade/Attic/upgrade-1.0.6-1.0.7d.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.0.6-1.0.7d.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,274 @@ +alter table forums_forums add column thread_count integer; +alter table forums_forums alter thread_count set default 0; + +alter table forums_forums add column approved_thread_count integer; +alter table forums_forums alter approved_thread_count set default 0; + +update forums_forums +set approved_thread_count = (select count(message_id) + from forums_messages_approved fm + where fm.forum_id=forums_forums.forum_id + and fm.parent_id is null), + thread_count = (select count(message_id) + from forums_messages fm + where fm.forum_id=forums_forums.forum_id + and fm.parent_id is null); + +alter table forums_messages add column reply_count integer; +alter table forums_messages alter reply_count set default 0; + +alter table forums_messages add column approved_reply_count integer; +alter table forums_messages alter approved_reply_count set default 0; + +-- Need to drop and recreate because Postgres doesn't allow one to change the +-- number of columns in a view when you do a "replace". + +drop view forums_forums_enabled; +create view forums_forums_enabled +as + select * + from forums_forums + where enabled_p = 't'; + +drop view forums_messages_approved; +create or replace view forums_messages_approved +as + select * + from forums_messages + where state = 'approved'; + +drop view forums_messages_pending; +create or replace view forums_messages_pending +as + select * + from forums_messages + where state= 'pending'; + +update forums_messages +set approved_reply_count = (select count(*) + from forums_messages_approved fm1 + where fm1.tree_sortkey + between tree_left(forums_messages.tree_sortkey) + and tree_right(forums_messages.tree_sortkey) + and forums_messages.forum_id = fm1.forum_id), + reply_count = (select count(*) + from forums_messages fm1 + where fm1.tree_sortkey + between tree_left(forums_messages.tree_sortkey) + and tree_right(forums_messages.tree_sortkey) + and forums_messages.forum_id = fm1.forum_id) +where parent_id is null; + +select define_function_args ('forums_message__new', 'message_id,object_type;forums_message,forum_id,subject,content,format,user_id,state,parent_id,creation_date,creation_user,creation_ip,context_id'); + +-- Get rid of the old version so we'll throw an error if the admin forgets to reboot +-- OpenACS after the upgrade (package_instantiate_object caches param lists) + +drop function forums_message__new (integer,varchar,integer,varchar,text,char,integer,timestamptz,varchar,integer,timestamptz,integer,varchar,integer); + +create or replace function forums_message__new (integer,varchar,integer,varchar,text,char,integer,varchar,integer,timestamptz,integer,varchar,integer) +returns integer as ' +declare + p_message_id alias for $1; + p_object_type alias for $2; + p_forum_id alias for $3; + p_subject alias for $4; + p_content alias for $5; + p_format alias for $6; + p_user_id alias for $7; + p_state alias for $8; + p_parent_id alias for $9; + p_creation_date alias for $10; + p_creation_user alias for $11; + p_creation_ip alias for $12; + p_context_id alias for $13; + v_message_id integer; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; +begin + v_message_id := acs_object__new( + p_message_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + coalesce(p_context_id, p_forum_id) + ); + + if p_state is null then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id = p_forum_id; + + if v_forum_policy = ''moderated'' + then v_state := ''pending''; + else v_state := ''approved''; + end if; + else + v_state := p_state; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, format, user_id, parent_id, state, last_child_post) + values + (v_message_id, p_forum_id, p_subject, p_content, p_format, p_user_id, p_parent_id, + v_state, current_timestamp); + + update forums_forums + set last_post = current_timestamp + where forum_id = p_forum_id; + + if p_parent_id is null then + if v_state = ''approved'' then + update forums_forums + set thread_count = thread_count + 1, + approved_thread_count = approved_thread_count + 1 + where forum_id=p_forum_id; + else + update forums_forums + set thread_count = thread_count + 1 + where forum_id=p_forum_id; + end if; + else + if v_state = ''approved'' then + update forums_messages + set approved_reply_count = approved_reply_count + 1, + reply_count = reply_count + 1, + last_child_post = current_timestamp + where message_id = forums_message__root_message_id(v_message_id); + else + update forums_messages + set reply_count = reply_count + 1, + last_child_post = current_timestamp + where message_id = forums_message__root_message_id(v_message_id); + end if; + end if; + + return v_message_id; + +end;' language 'plpgsql'; + +select define_function_args ('forums_message__set_state', 'message_id,state'); + +create or replace function forums_message__set_state(integer,varchar) returns integer as ' +declare + p_message_id alias for $1; + p_state alias for $2; + v_cur record; +begin + + select into v_cur * + from forums_messages + where message_id = p_message_id; + + if v_cur.parent_id is null then + if p_state = ''approved'' and v_cur.state <> ''approved'' then + update forums_forums + set approved_thread_count = approved_thread_count + 1 + where forum_id=v_cur.forum_id; + elsif p_state <> ''approved'' and v_cur.state = ''approved'' then + update forums_forums + set approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + else + if p_state = ''approved'' and v_cur.state <> ''approved'' then + update forums_messages + set approved_reply_count = approved_reply_count + 1 + where message_id = forums_message__root_message_id(v_cur.message_id); + elsif p_state <> ''approved'' and v_cur.state = ''approved'' then + update forums_messages + set approved_reply_count = approved_reply_count - 1 + where message_id = forums_message__root_message_id(v_cur.message_id); + end if; + end if; + + update forums_messages + set state = p_state + where message_id = p_message_id; + + return 0; + +end;' language 'plpgsql'; + +create or replace function forums_message__delete (integer) +returns integer as ' +declare + p_message_id alias for $1; + v_cur record; +begin + + -- Maintain the forum thread counts + + select into v_cur * + from forums_messages + where message_id = p_message_id; + + if v_cur.parent_id is null then + if v_cur.state = ''approved'' then + update forums_forums + set thread_count = thread_count - 1, + approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + else + update forums_forums + set thread_count = thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + elsif v_cur.state = ''approved'' then + update forums_messages + set approved_reply_count = approved_reply_count - 1, + reply_count = reply_count - 1 + where message_id = forums_message__root_message_id(v_cur.message_id); + else + update forums_messages + set reply_count = reply_count - 1 + where message_id = forums_message__root_message_id(v_cur.message_id); + end if; + + perform acs_object__delete(p_message_id); + return 0; + +end;' language 'plpgsql'; + +select define_function_args ('forums_message__delete_thread', 'message_id'); + +create or replace function forums_message__delete_thread (integer) +returns integer as ' +declare + p_message_id alias for $1; + v_forum_id forums_messages.forum_id%TYPE; + v_sortkey forums_messages.tree_sortkey%TYPE; + v_message RECORD; +begin + select forum_id, tree_sortkey + into v_forum_id, v_sortkey + from forums_messages + where message_id = p_message_id; + + -- if it is already deleted + if v_forum_id is null + then return 0; + end if; + + -- delete all children + -- order by tree_sortkey desc to guarantee + -- that we never delete a parent before its child + -- sortkeys are beautiful + for v_message in select * + from forums_messages + where forum_id = v_forum_id + and tree_sortkey between tree_left(v_sortkey) and tree_right(v_sortkey) + order by tree_sortkey desc + loop + -- Avoid the count bookkeeping down in forums_message__delete + perform forums_message__delete(v_message.message_id); + end loop; + + -- delete the message itself + perform forums_message__delete(p_message_id); + + return 0; +end;' language 'plpgsql'; + Index: openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.0d4-1.0.1d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/upgrade/Attic/upgrade-1.0d4-1.0.1d2.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.0d4-1.0.1d2.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,99 @@ +alter table forums_messages add format varchar(30); +alter table forums_messages alter column format set default 'text/plain'; +alter table forums_messages add constraint forums_mess_format_ck check (format in ('text/enhanced', 'text/plain', 'text/fixed-width', 'text/html')); + +update forums_messages +set format = 'text/html' +where html_p = 't'; +update forums_messages +set format = 'text/plain' +where html_p = 'f'; + +alter table forums_messages drop column html_p cascade; + +-- recreate the views +create or replace view forums_messages_approved +as + select * + from forums_messages + where state = 'approved'; + +create or replace view forums_messages_pending +as + select * + from forums_messages + where state= 'pending'; + + +-- taken from forums-messages-package-create.sql + +select define_function_args ('forums_message__new', 'message_id,object_type;forums_message,forum_id,subject,content,format,user_id,posting_date,state,parent_id,creation_date,creation_user,creation_ip,context_id'); + +create or replace function forums_message__new (integer,varchar,integer,varchar,text,char,integer,timestamptz,varchar,integer,timestamptz,integer,varchar,integer) +returns integer as ' +declare + p_message_id alias for $1; + p_object_type alias for $2; + p_forum_id alias for $3; + p_subject alias for $4; + p_content alias for $5; + p_format alias for $6; + p_user_id alias for $7; + p_posting_date alias for $8; + p_state alias for $9; + p_parent_id alias for $10; + p_creation_date alias for $11; + p_creation_user alias for $12; + p_creation_ip alias for $13; + p_context_id alias for $14; + v_message_id integer; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; + v_posting_date forums_messages.posting_date%TYPE; +begin + v_message_id := acs_object__new( + p_message_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + coalesce(p_context_id, p_forum_id) + ); + + if p_state is null then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id = p_forum_id; + + if v_forum_policy = ''moderated'' + then v_state := ''pending''; + else v_state := ''approved''; + end if; + else + v_state := p_state; + end if; + + if p_posting_date is null then + v_posting_date = now(); + else + v_posting_date = p_posting_date; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, format, user_id, posting_date, parent_id, state) + values + (v_message_id, p_forum_id, p_subject, p_content, p_format, p_user_id, v_posting_date, p_parent_id, v_state); + + update forums_forums + set last_post = v_posting_date + where forum_id = p_forum_id; + + update forums_messages + set last_child_post = v_posting_date + where message_id = forums_message__root_message_id(v_message_id); + + return v_message_id; + +end; +' language 'plpgsql'; Index: openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.1.1-1.1.2d1.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/upgrade/Attic/upgrade-1.1.1-1.1.2d1.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.1.1-1.1.2d1.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,35 @@ +update acs_permissions + set privilege = 'read' + where privilege = 'forum_read' + and not exists (select 1 + from acs_permissions p1 + where p1.object_id = acs_permissions.object_id + and p1.grantee_id = acs_permissions.grantee_id + and p1.privilege = 'read'); + +delete from acs_permissions + where privilege = 'forum_read'; + +update acs_permissions + set privilege = 'write' + where privilege = 'forum_write' + and not exists (select 1 + from acs_permissions p1 + where p1.object_id = acs_permissions.object_id + and p1.grantee_id = acs_permissions.grantee_id + and p1.privilege = 'write'); + +delete from acs_permissions + where privilege = 'forum_write'; + +update acs_permissions + set privilege = 'create' + where privilege = 'forum_create' + and not exists (select 1 + from acs_permissions p1 + where p1.object_id = acs_permissions.object_id + and p1.grantee_id = acs_permissions.grantee_id + and p1.privilege = 'create'); + +delete from acs_permissions + where privilege = 'forum_create'; Index: openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.1.2d4-1.1.2d5.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/upgrade/Attic/upgrade-1.1.2d4-1.1.2d5.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.1.2d4-1.1.2d5.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,52 @@ +-- +-- Most of the forum_* privileges are now deprecated. A notable exception is +-- forum_moderate, which is little used but provides a way to grant moderation +-- privileges without granting full admin privileges. +-- + +update acs_permissions +set privilege = 'read' +where privilege = 'forum_read'; + +update acs_permissions +set privilege = 'write' +where privilege = 'forum_write'; + +update acs_permissions +set privilege = 'create' +where privilege = 'forum_create'; + +update acs_permissions +set privilege = 'delete' +where privilege = 'forum_delete'; + +-- As best as we can tell this is never used even though it's granted +-- by dotlrn-forums. + +delete from acs_permissions where privilege = 'forum_post'; + +create function inline_0 () +returns integer as' +begin + perform acs_privilege__remove_child(''read'',''forum_read''); + perform acs_privilege__remove_child(''create'',''forum_create''); + perform acs_privilege__remove_child(''write'',''forum_write''); + perform acs_privilege__remove_child(''delete'',''forum_delete''); + perform acs_privilege__remove_child(''forum_moderate'',''forum_read''); + perform acs_privilege__remove_child(''forum_moderate'',''forum_post''); + perform acs_privilege__remove_child(''forum_write'',''forum_read''); + perform acs_privilege__remove_child(''forum_write'',''forum_post''); + + perform acs_privilege__drop_privilege(''forum_read''); + perform acs_privilege__drop_privilege(''forum_create''); + perform acs_privilege__drop_privilege(''forum_write''); + perform acs_privilege__drop_privilege(''forum_post''); + perform acs_privilege__drop_privilege(''forum_delete''); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); + + Index: openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.1d1-1.1d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/upgrade/Attic/upgrade-1.1d1-1.1d2.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.1d1-1.1d2.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,119 @@ +-- replace new functions with ones that set acs_object.title, package_id + +create or replace function forums_forum__new (integer,varchar,varchar,varchar,varchar,varchar,integer,timestamptz,integer,varchar,integer) +returns integer as ' +declare + p_forum_id alias for $1; + p_object_type alias for $2; + p_name alias for $3; + p_charter alias for $4; + p_presentation_type alias for $5; + p_posting_policy alias for $6; + p_package_id alias for $7; + p_creation_date alias for $8; + p_creation_user alias for $9; + p_creation_ip alias for $10; + p_context_id alias for $11; + v_forum_id integer; +begin + v_forum_id:= acs_object__new( + p_forum_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + coalesce(p_context_id, p_package_id), + ''t'', + p_name, + p_package_id + ); + + insert into forums_forums + (forum_id, name, charter, presentation_type, posting_policy, package_id) + values + (v_forum_id, p_name, p_charter, p_presentation_type, p_posting_policy, p_package_id); + + return v_forum_id; +end; +' language 'plpgsql'; + + +create or replace function forums_message__new (integer,varchar,integer,varchar,text,char,integer,timestamptz,varchar,integer,timestamptz,integer,varchar,integer) +returns integer as ' +declare + p_message_id alias for $1; + p_object_type alias for $2; + p_forum_id alias for $3; + p_subject alias for $4; + p_content alias for $5; + p_html_p alias for $6; + p_user_id alias for $7; + p_posting_date alias for $8; + p_state alias for $9; + p_parent_id alias for $10; + p_creation_date alias for $11; + p_creation_user alias for $12; + p_creation_ip alias for $13; + p_context_id alias for $14; + v_message_id integer; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; + v_posting_date forums_messages.posting_date%TYPE; + v_package_id acs_objects.package_id%TYPE; +begin + + select package_id into v_package_id from forums_forums where forum_id = p_forum_id; + + if v_package_id is null then + raise exception ''forums_message__new: forum_id % not found'', p_forum_id; + end if; + + v_message_id := acs_object__new( + p_message_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + coalesce(p_context_id, p_forum_id), + ''t'', + p_subject, + v_package_id + ); + + if p_state is null then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id = p_forum_id; + + if v_forum_policy = ''moderated'' + then v_state := ''pending''; + else v_state := ''approved''; + end if; + else + v_state := p_state; + end if; + + if p_posting_date is null then + v_posting_date = now(); + else + v_posting_date = p_posting_date; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, html_p, user_id, posting_date, parent_id, state) + values + (v_message_id, p_forum_id, p_subject, p_content, p_html_p, p_user_id, v_posting_date, p_parent_id, v_state); + + update forums_forums + set last_post = v_posting_date + where forum_id = p_forum_id; + + update forums_messages + set last_child_post = v_posting_date + where message_id = forums_message__root_message_id(v_message_id); + + return v_message_id; + +end; +' language 'plpgsql'; Index: openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.2d1-1.2d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/upgrade/Attic/upgrade-1.2d1-1.2d2.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.2d1-1.2d2.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,238 @@ +-- @author Jeff Davis davis@xarg.net +-- +-- bug 1807 last_poster rather than first poster should be shown in forums index page +-- add a last_poster to support this and update triggers to support it. + +alter table forums_messages add column last_poster integer + constraint forums_mess_last_poster_fk + references users(user_id); + +-- Now populate the new column +-- this depends on last_child_post being properly set. +-- use min(user_id) just in case there are two that have the same timestamp) + +update forums_messages set last_poster = (select min(user_id) + from forums_messages fm1 + where fm1.posting_date = forums_messages.last_child_post + and forums_messages.forum_id = fm1.forum_id + and fm1.tree_sortkey + between tree_left(forums_messages.tree_sortkey) + and tree_right(forums_messages.tree_sortkey) ) +where parent_id is null; + +-- the better method above fails for some things (like notably openacs.org where +-- the last_child_post may not exist in the child posts due to import and upgrade +-- glitches. try this one which will give us a name no matter what. +update forums_messages +set last_poster = (select user_id + from forums_messages fm1 + where fm1.message_id = (select max(message_id) + from forums_messages fm2 + where forums_messages.forum_id = fm2.forum_id + and fm2.tree_sortkey + between tree_left(forums_messages.tree_sortkey) + and tree_right(forums_messages.tree_sortkey) )) +where parent_id is null and last_poster is null; + + +-- Need to drop and recreate because Postgres doesn't allow one to change the +-- number of columns in a view when you do a "replace". +drop view forums_messages_approved; +create or replace view forums_messages_approved +as + select * + from forums_messages + where state = 'approved'; + +drop view forums_messages_pending; +create or replace view forums_messages_pending +as + select * + from forums_messages + where state= 'pending'; + + +-- +-- Replace the procs which manipulate state and new message to save last_poster. +-- +create or replace function forums_message__new (integer,varchar,integer,varchar,text,char,integer,varchar,integer,timestamptz,integer,varchar,integer) +returns integer as ' +declare + p_message_id alias for $1; + p_object_type alias for $2; + p_forum_id alias for $3; + p_subject alias for $4; + p_content alias for $5; + p_format alias for $6; + p_user_id alias for $7; + p_state alias for $8; + p_parent_id alias for $9; + p_creation_date alias for $10; + p_creation_user alias for $11; + p_creation_ip alias for $12; + p_context_id alias for $13; + v_message_id integer; + v_forum_policy forums_forums.posting_policy%TYPE; + v_state forums_messages.state%TYPE; + v_posting_date forums_messages.posting_date%TYPE; + v_package_id acs_objects.package_id%TYPE; +begin + + select package_id into v_package_id from forums_forums where forum_id = p_forum_id; + + if v_package_id is null then + raise exception ''forums_message__new: forum_id % not found'', p_forum_id; + end if; + + v_message_id := acs_object__new( + p_message_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + coalesce(p_context_id, p_forum_id), + ''t'', + p_subject, + v_package_id + ); + + if p_state is null then + select posting_policy + into v_forum_policy + from forums_forums + where forum_id = p_forum_id; + + if v_forum_policy = ''moderated'' + then v_state := ''pending''; + else v_state := ''approved''; + end if; + else + v_state := p_state; + end if; + + insert into forums_messages + (message_id, forum_id, subject, content, format, user_id, parent_id, state, last_child_post, last_poster) + values + (v_message_id, p_forum_id, p_subject, p_content, p_format, p_user_id, p_parent_id, + v_state, current_timestamp, p_user_id); + + update forums_forums + set last_post = current_timestamp + where forum_id = p_forum_id; + + if p_parent_id is null then + if v_state = ''approved'' then + update forums_forums + set thread_count = thread_count + 1, + approved_thread_count = approved_thread_count + 1 + where forum_id=p_forum_id; + else + update forums_forums + set thread_count = thread_count + 1 + where forum_id=p_forum_id; + end if; + else + if v_state = ''approved'' then + update forums_messages + set approved_reply_count = approved_reply_count + 1, + reply_count = reply_count + 1, + last_poster = p_user_id, + last_child_post = current_timestamp + where message_id = forums_message__root_message_id(v_message_id); + else + -- dont update last_poster, last_child_post when not approved + update forums_messages + set reply_count = reply_count + 1 + where message_id = forums_message__root_message_id(v_message_id); + end if; + end if; + + return v_message_id; + +end;' language 'plpgsql'; + +select define_function_args ('forums_message__set_state', 'message_id,state'); + +create or replace function forums_message__set_state(integer,varchar) returns integer as ' +declare + p_message_id alias for $1; + p_state alias for $2; + v_cur record; +begin + + select into v_cur * + from forums_messages + where message_id = p_message_id; + + if v_cur.parent_id is null then + if p_state = ''approved'' and v_cur.state <> ''approved'' then + update forums_forums + set approved_thread_count = approved_thread_count + 1 + where forum_id=v_cur.forum_id; + elsif p_state <> ''approved'' and v_cur.state = ''approved'' then + update forums_forums + set approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + else + if p_state = ''approved'' and v_cur.state <> ''approved'' then + update forums_messages + set approved_reply_count = approved_reply_count + 1, + last_poster = (case when v_cur.posting_date > last_child_post then v_cur.user_id else last_poster end), + last_child_post = (case when v_cur.posting_date > last_child_post then v_cur.posting_date else last_child_post end) + where message_id = forums_message__root_message_id(v_cur.message_id); + elsif p_state <> ''approved'' and v_cur.state = ''approved'' then + update forums_messages + set approved_reply_count = approved_reply_count - 1 + where message_id = forums_message__root_message_id(v_cur.message_id); + end if; + end if; + + update forums_messages + set state = p_state + where message_id = p_message_id; + + return 0; + +end;' language 'plpgsql'; + +select define_function_args ('forums_message__delete', 'message_id'); + +create or replace function forums_message__delete (integer) +returns integer as ' +declare + p_message_id alias for $1; + v_cur record; +begin + + -- Maintain the forum thread counts + + select into v_cur * + from forums_messages + where message_id = p_message_id; + + if v_cur.parent_id is null then + if v_cur.state = ''approved'' then + update forums_forums + set thread_count = thread_count - 1, + approved_thread_count = approved_thread_count - 1 + where forum_id=v_cur.forum_id; + else + update forums_forums + set thread_count = thread_count - 1 + where forum_id=v_cur.forum_id; + end if; + elsif v_cur.state = ''approved'' then + update forums_messages + set approved_reply_count = approved_reply_count - 1, + reply_count = reply_count - 1 + where message_id = forums_message__root_message_id(v_cur.message_id); + else + update forums_messages + set reply_count = reply_count - 1 + where message_id = forums_message__root_message_id(v_cur.message_id); + end if; + + perform acs_object__delete(p_message_id); + return 0; +end;' language 'plpgsql'; Index: openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.2d2-1.2d3.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/sql/postgresql/upgrade/Attic/upgrade-1.2d2-1.2d3.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/sql/postgresql/upgrade/upgrade-1.2d2-1.2d3.sql 23 Jan 2007 13:24:05 -0000 1.1 @@ -0,0 +1,4 @@ +CREATE INDEX forums_forums_pkg_enable_idx + ON forums_forums + USING btree + (package_id, enabled_p); Index: openacs-4/contrib/packages/forums/tcl/form-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/form-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/form-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,187 @@ +ad_library { + + Reusable forms in the forums package + + @author lee@thaum.net + @creation-date 2003-11-12 +} + +namespace eval forums {} +namespace eval forums::form {} + +ad_proc -public forums::form::message { + {-optional:boolean} + {-prefix {}} + form_name +} { + adds form elements to form_name which represent the data held in a forum + message +} { + + ############################## + # Form definition + # + + if { $optional_p } { + set optional_switch "-optional" + } else { + set optional_switch "" + } + + template::element create $form_name ${prefix}subject \ + -label [_ forums.Subject] \ + -datatype text \ + -widget text \ + -html {size 60} \ + $optional_switch + + template::element create $form_name ${prefix}message_body \ + -label [_ forums.Body] \ + -datatype richtext \ + -widget richtext \ + -html {rows 20 cols 100 wrap soft} \ + -htmlarea_p 1 \ + -options {editor xinha plugins { + GetHtml CharacterMap ContextMenu FullScreen InsertAnchor + ListType TableOperations EditTag LangMarks Abbreviation OacsFs + } height 350px } \ + $optional_switch + +} + +ad_proc -public forums::form::post_message { + {-optional:boolean} + {-show_anonymous_p 1} + {-show_attachments_p 1} + {-prefix {}} + form_name +} { + adds form elements to a form for the default post message form +} { + template::element create $form_name ${prefix}forum_id \ + -label [_ forums.forum_ID] \ + -datatype integer \ + -widget hidden + + template::element create $form_name ${prefix}parent_id \ + -label [_ forums.parent_ID] \ + -datatype integer \ + -widget hidden \ + -optional + + template::element create $form_name ${prefix}subscribe_p \ + -label [_ forums.Subscribe] \ + -datatype text \ + -widget hidden \ + -optional + + set options [list [list [_ forums.post_anonymously] 1 ] ] + + template::element create $form_name ${prefix}anonymous_p \ + -label [_ forums.Anonymous] \ + -datatype integer \ + -widget [ad_decode $show_anonymous_p 0 "hidden" "checkbox"] \ + -options $options \ + -optional + + set options [list [list [_ forums.No] 0] [list [_ forums.Yes] 1]] + + template::element create $form_name ${prefix}attach_p \ + -label [_ forums.Attach] \ + -datatype text \ + -widget [ad_decode $show_attachments_p 0 "hidden" "radio"] \ + -options $options + + if {$optional_p} { + template::element set_properties $form_name ${prefix}forum_id -optional + template::element set_properties $form_name ${prefix}attach_p -optional + } +} + +ad_proc -public forums::form::forward_message { + {-prefix {}} + form_name +} { + adds form elements to form_name to allow the user to enter the details + of a message they want to forward by email +} { + template::element create $form_name ${prefix}to_email \ + -label [_ forums.Email] \ + -datatype text \ + -widget text \ + -html {size 60} + + template::element create $form_name ${prefix}subject \ + -label [_ forums.Subject] \ + -datatype text \ + -widget text \ + -html {size 80} + + template::element create $form_name ${prefix}pre_body \ + -label [_ forums.Your_Note] \ + -datatype text \ + -widget textarea \ + -html {cols 80 rows 10 wrap hard} +} + +ad_proc -public forums::form::search { + {-prefix {}} + form_name +} { + Constructs the elements of a form for searching for a term + optionally in a particular forum +} { + template::element create $form_name ${prefix}search_text \ + -label [_ forums.Search_1] \ + -datatype text \ + -widget text + + template::element create $form_name ${prefix}forum_id \ + -label [_ forums.ForumID] \ + -datatype text \ + -widget hidden \ + -optional +} + +ad_proc -public forums::form::forum { + {-prefix {}} + form_name +} { + Constructs the elements of a form for creating/editing a forum +} { + template::element create $form_name ${prefix}name \ + -label [_ forums.Name] \ + -datatype text \ + -widget text \ + -html {size 60} \ + -validate { {expr ![empty_string_p [string trim $value]]} {Forum Name can not be blank} } + + template::element create $form_name ${prefix}charter \ + -label [_ forums.Charter] \ + -datatype richtext \ + -widget richtext \ + -html {cols 60 rows 20 wrap soft} \ + -validate { {expr [string length $value] <= 4000 } {#forums.charter_max_chars#} } \ + -optional + + template::element create $form_name ${prefix}presentation_type \ + -label [_ forums.Presexntation] \ + -datatype text \ + -widget select \ + -help_text [_ forums.help_presentation] \ + -options [list [list [_ forums.Flat] flat] [list [_ forums.Threaded] threaded]] + + template::element create $form_name ${prefix}posting_policy \ + -label [_ forums.Posting_Policy] \ + -datatype text \ + -widget select \ + -help_text [_ forums.help_posting_policy] \ + -options [list [list [_ forums.open] open] [list [_ forums.moderated] moderated] [list [_ forums.closed] closed] ] + + template::element create $form_name ${prefix}new_threads_p \ + -label [_ forums.lt_Users_Can_Create_New_] \ + -datatype integer \ + -widget radio \ + -help_text [_ forums.help_new_threads] \ + -options [list [list [_ forums.Yes] 1] [list [_ forums.No] 0] ] +} Index: openacs-4/contrib/packages/forums/tcl/forum-message-reply-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forum-message-reply-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forum-message-reply-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,29 @@ +ad_library { + + Forums Library - Reply Handling + + @creation-date 2002-05-17 + @author Ben Adida + @cvs-id $Id: forum-message-reply-procs.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} + +namespace eval forum::message::notification { + + ad_proc -public get_url { + object_id + } { + + } + + ad_proc -public process_reply { + reply_id + } { + + } + + +} + + + Index: openacs-4/contrib/packages/forums/tcl/forum-reply-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forum-reply-procs-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forum-reply-procs-oracle.xql 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,26 @@ + + + oracle8.1.6 + + + + select site_node.url(node_id) + from site_nodes + where object_id = (select package_id + from forums_forums + where forums_forums.forum_id = :forum_id) + + + + + + + + + + + + + + + Index: openacs-4/contrib/packages/forums/tcl/forum-reply-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forum-reply-procs-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forum-reply-procs-postgresql.xql 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,18 @@ + + + postgresql7.1 + + + + select site_node__url(node_id) + from site_nodes + where object_id = (select package_id + from forums_forums + where forums_forums.forum_id = :forum_id) + + + + + + + Index: openacs-4/contrib/packages/forums/tcl/forum-reply-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forum-reply-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forum-reply-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,64 @@ +ad_library { + + Forums Library - Reply Handling + + @creation-date 2002-05-17 + @author Ben Adida + @cvs-id $Id: forum-reply-procs.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} + +namespace eval forum::notification { + + ad_proc -public get_url { + object_id + } { + returns a full url to the object_id. + handles messages and forums. + } { + + set object_type [db_string select_object_type {}] + + if {[string compare $object_type "forums_message"] == 0} { + + # object is a message + set message_id $object_id + forum::message::get -message_id $message_id -array message + set forum_id $message(forum_id) + set forum_url "[ad_url][db_string select_forums_package_url {}]" + return ${forum_url}message-view?message_id=$message(root_message_id) + + } else { + + # object_type is a forum + set forum_id $object_id + set forum_url "[ad_url][db_string select_forums_package_url {}]" + return ${forum_url}forum-view?forum_id=$forum_id + + } + } + + ad_proc -public process_reply { + reply_id + } { + ns_log debug "forum::notification::process_reply: processing reply $reply_id" + + # Get the data + notification::reply::get -reply_id $reply_id -array reply + + # Get the message information + forum::message::get -message_id $reply(object_id) -array message + + # Insert the message + forum::message::new -forum_id $message(forum_id) \ + -parent_id $message(message_id) \ + -subject $reply(subject) \ + -content [ad_html_to_text -- $reply(content)] \ + -user_id $reply(from_user) + } + + +} + + + Index: openacs-4/contrib/packages/forums/tcl/forum-reply-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forum-reply-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forum-reply-procs.xql 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,22 @@ + + + + + + select object_type + from acs_objects + where object_id = :object_id + + + + + + + + + + + + + + Index: openacs-4/contrib/packages/forums/tcl/forums-callback-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forums-callback-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forums-callback-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,159 @@ +ad_library { + Library of callbacks implementations + for Forums + + Navigation callbacks. + + @author Jeff Davis + @creation-date 2005-03-11 + @cvs-id $Id: forums-callback-procs.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ +} + +ad_proc -public -callback navigation::package_admin -impl forums {} { + return the admin actions for the forum package. +} { + set actions {} + + # Check for admin on the package... + if {[permission::permission_p -object_id $package_id -privilege admin -party_id $user_id]} { + lappend actions [list LINK admin/ [_ acs-kernel.common_Administration] {} [_ forums.Admin_for_all]] + + lappend actions [list LINK \ + [export_vars -base admin/permissions {{object_id $package_id}}] \ + [_ acs-kernel.common_Permissions] {} [_ forums.Permissions_for_all]] + lappend actions [list LINK admin/forum-new [_ forums.Create_a_New_Forum] {} {}] + } + + # check for admin on the individual forums. + db_foreach forums { + select forum_id, name, enabled_p + from forums_forums + where package_id = :package_id + and exists (select 1 from acs_object_party_privilege_map pm + where pm.object_id = forum_id + and pm.party_id = :user_id + and pm.privilege = 'admin') + } { + lappend actions [list SECTION "Forum $name ([ad_decode $enabled_p t [_ forums.enabled] [_ forums.disabled]])" {}] + + lappend actions [list LINK [export_vars -base admin/forum-edit forum_id] \ + [_ forums.Edit_forum_name] {} {}] + lappend actions [list LINK [export_vars -base admin/permissions {{object_id $forum_id} return_url}] \ + [_ forums.Permission_forum_name] {} {}] + } + return $actions +} + + +ad_proc -callback merge::MergeShowUserInfo -impl forums { + -user_id:required +} { + Merge the *forums* of two users. + The from_user_id is the user_id of the user + that will be deleted and all the *forums* + of this user will be mapped to the to_user_id. + +} { + set msg "Forums items of $user_id" + ns_log Notice $msg + set result [list $msg] + + set last_poster [db_list_of_lists sel_poster {*SQL*} ] + set msg "Last Poster of $last_poster" + lappend result $msg + + set poster [db_list_of_lists sel_user_id {*SQL*} ] + set msg "Poster of $poster" + lappend result $msg + + return $result +} + +ad_proc -callback merge::MergePackageUser -impl forums { + -from_user_id:required + -to_user_id:required +} { + Merge the *forums* of two users. + The from_user_id is the user_id of the user + that will be deleted and all the *forums* + of this user will be mapped to the to_user_id. + +} { + set msg "Merging forums" + ns_log Notice $msg + set result [list $msg] + + db_dml upd_poster { *SQL* } + db_dml upd_user_id { *SQL* } + + lappend result "Merge of forums is done" + + return $result +} + +#Callbacks for application-track + +ad_proc -callback application-track::getApplicationName -impl forums {} { + callback implementation + } { + return "forums" + } + +ad_proc -callback application-track::getGeneralInfo -impl forums {} { + callback implementation + } { + db_1row my_query { + select count(f.forum_id) as result + FROM forums_forums f, dotlrn_communities_full com + WHERE com.community_id=:comm_id + and apm_package__parent_id(f.package_id) = com.package_id + } + + return "$result" + } + +ad_proc -callback application-track::getSpecificInfo -impl forums {} { + callback implementation + } { + + upvar $query_name my_query + upvar $elements_name my_elements + + set my_query { + SELECT f.name as name,f.thread_count as threads, + f.last_post, + to_char(o.creation_date, 'YYYY-MM-DD HH24:MI:SS') as creation_date + FROM forums_forums f,dotlrn_communities_full com,acs_objects o + WHERE com.community_id=:class_instance_id + and f.forum_id = o.object_id + and apm_package__parent_id(f.package_id) = com.package_id + } + + set my_elements { + name { + label "Name" + display_col name + html {align center} + + } + threads { + label "Threads" + display_col threads + html {align center} + } + creation_date { + label "creation_date" + display_col creation_date + html {align center} + } + last_post { + label "last_post" + display_col last_post + html {align center} + } + + + } + + return "OK" + } Index: openacs-4/contrib/packages/forums/tcl/forums-callback-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forums-callback-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forums-callback-procs.xql 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,36 @@ + + + + + + update forums_messages + set last_poster = :to_user_id + where last_poster = :from_user_id + + + + + + update forums_messages + set user_id = :to_user_id + where user_id = :from_user_id + + + + + + select message_id, subject + from forums_messages + where user_id = :user_id + + + + + + select message_id, subject + from forums_messages + where last_poster = :user_id + + + + Index: openacs-4/contrib/packages/forums/tcl/forums-email-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forums-email-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forums-email-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,37 @@ +ad_library { + + Forums Library + + @creation-date 2002-05-17 + @author Ben Adida + @cvs-id $Id: forums-email-procs.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} + +namespace eval forum { namespace eval email {} } + +ad_proc -public forum::email::create_forward_email { + {-pre_body:required} + message_passed +} { + create email content to forward a message +} { + # Get the message data array + upvar $message_passed message + + # Variables for I18N message lookup: + set posting_date $message(posting_date_ansi) + set user_name $message(user_name) + + # Set up the message body + set new_body "[ad_html_to_text -- $pre_body]" + append new_body "\n\n===================================\n\n" + append new_body "[_ forums.email_alert_body_header] +[_ forums.Forum_1] $message(forum_name) +Thread: $message(root_subject)\n\n" + append new_body [ad_html_text_convert -from $message(format) -to text/plain -- $message(content)] + + append new_body "\n\n-- \n[ad_url][ad_conn package_url]message-view?[export_vars -anchor $message(message_id) [list [list message_id $message(root_message_id)]]]\n" + + return $new_body +} Index: openacs-4/contrib/packages/forums/tcl/forums-install-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forums-install-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forums-install-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,65 @@ +ad_library { + Forums install callbacks + + @creation-date 2004-04-01 + @author Jeff Davis davis@xarg.net + @cvs-id $Id: forums-install-procs.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ +} + +namespace eval forum::install {} + +ad_proc -private forum::install::package_install {} { + package install callback +} { + forum::sc::register_implementations +} + +ad_proc -private forum::install::package_uninstall {} { + package uninstall callback +} { + forum::sc::unregister_implementations +} + +ad_proc -private forum::install::package_upgrade { + {-from_version_name:required} + {-to_version_name:required} +} { + Package before-upgrade callback +} { + apm_upgrade_logic \ + -from_version_name $from_version_name \ + -to_version_name $to_version_name \ + -spec { + 1.1d3 1.1d4 { + # just need to install the forum_forum callback + forum::sc::register_forum_fts_impl + } + } +} + +ad_proc -private ::install::xml::action::forum-create { node } { + Create a forum instance from an install.xml file +} { + set url [apm_required_attribute_value $node url] + set name [apm_required_attribute_value $node name] + set presentation [apm_attribute_value -default "flat" $node presentation] + set id [apm_attribute_value -default "" $node id] + set posting_policy [apm_attribute_value -default "open" $node posting-policy] + + + set charter_node [lindex [xml_node_get_children_by_name [lindex $node 0] charter] 0] + set charter [xml_node_get_content $charter_node] + + set package_id [site_node::get_element -url $url -element package_id] + + set forum_id [forum::new \ + -name $name \ + -charter $charter \ + -presentation_type $presentation \ + -posting_policy $posting_policy \ + -package_id $package_id] + + if {![string equal $id ""]} { + set ::install::xml::ids($id) $forum_id + } +} Index: openacs-4/contrib/packages/forums/tcl/forums-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forums-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forums-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,152 @@ +ad_library { + + Forums Library + + @creation-date 2002-05-17 + @author Ben Adida + @cvs-id $Id: forums-procs.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} + +namespace eval forum {} + + +ad_proc -public forum::new { + {-forum_id ""} + {-name:required} + {-charter ""} + {-presentation_type flat} + {-posting_policy open} + {-package_id:required} +} { + create a new forum +} { + set var_list [list \ + [list forum_id $forum_id] \ + [list name $name] \ + [list charter $charter] \ + [list presentation_type $presentation_type] \ + [list posting_policy $posting_policy] \ + [list package_id $package_id]] + return [package_instantiate_object -var_list $var_list forums_forum] +} + +ad_proc -public forum::edit { + {-forum_id:required} + {-name:required} + {-charter ""} + {-presentation_type flat} + {-posting_policy open} +} { + edit a forum +} { + # This is a straight DB update + db_dml update_forum {} + db_dml update_forum_object {} +} + +ad_proc -public forum::attachments_enabled_p {} { + if {[string eq forums [ad_conn package_key]]} { + set package_id [site_node_apm_integration::child_package_exists_p \ + -package_key attachments + ] + } else { + return 0 + } +} + +ad_proc -public forum::list_forums { + {-package_id:required} +} { + List all forums in a package +} { + return [db_list_of_ns_sets select_forums {}] +} + +ad_proc -public forum::get { + {-forum_id:required} + {-array:required} +} { + get the fields for a forum + + @return +} { + # Select the info into the upvar'ed Tcl Array + upvar $array row + if {![db_0or1row select_forum {} -column_array row]} { + error "Forum $forum_id not found" {} NOT_FOUND + } +} + +ad_proc -public forum::posting_policy_set { + {-posting_policy:required} + {-forum_id:required} +} { + # JCD: this is potentially bad since we are + # just assuming registered_users is the + # right group to be granting write to. + + if {![string equal closed $posting_policy]} { + permission::grant -object_id $forum_id \ + -party_id [acs_magic_object registered_users] \ + -privilege write + } else { + permission::revoke -object_id $forum_id \ + -party_id [acs_magic_object registered_users] \ + -privilege write + } + +} + +ad_proc -public forum::new_questions_allow { + {-forum_id:required} + {-party_id ""} +} { + if { [empty_string_p $party_id] } { + set party_id [acs_magic_object registered_users] + } + # Give the public the right to ask new questions + permission::grant -object_id $forum_id \ + -party_id $party_id \ + -privilege create + util_memoize_flush_regexp $forum_id +} + +ad_proc -public forum::new_questions_deny { + {-forum_id:required} + {-party_id ""} +} { + if { [empty_string_p $party_id] } { + set party_id [acs_magic_object registered_users] + } + # Revoke the right from the public to ask new questions + permission::revoke -object_id $forum_id \ + -party_id $party_id \ + -privilege create + util_memoize_flush_regexp $forum_id +} + +ad_proc -public forum::new_questions_allowed_p { + {-forum_id:required} + {-party_id ""} +} { + if { [empty_string_p $party_id] } { + set party_id [acs_magic_object registered_users] + } + permission::permission_p -object_id $forum_id \ + -party_id $party_id \ + -privilege create +} + +ad_proc -public forum::enable { + {-forum_id:required} +} { + # Enable the forum, no big deal + db_dml update_forum_enabled_p {} +} + +ad_proc -public forum::disable { + {-forum_id:required} +} { + db_dml update_forum_disabled_p {} +} Index: openacs-4/contrib/packages/forums/tcl/forums-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forums-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forums-procs.xql 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,59 @@ + + + + + + update forums_forums + set name= :name, + charter= :charter, + presentation_type= :presentation_type, + posting_policy= :posting_policy + where forum_id = :forum_id + + + + + + update acs_objects + set title= :name + where object_id = :forum_id + + + + + + select forum_id, + name, + posting_policy, + presentation_type + from forums_forums + where package_id = :package_id + order by name + + + + + + select forums_forums.* + from forums_forums + where forums_forums.forum_id = :forum_id + + + + + + update forums_forums + set enabled_p = 't' + where forum_id = :forum_id + + + + + + update forums_forums + set enabled_p = 'f' + where forum_id = :forum_id + + + + Index: openacs-4/contrib/packages/forums/tcl/forums-sc-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forums-sc-procs-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forums-sc-procs-postgresql.xql 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,46 @@ + + + + postgresql7.1 + + + + select site_node__url(node_id) + from site_nodes + where object_id = (select package_id + from forums_forums + where forums_forums.forum_id = :forum_id) + + + + + + select site_node__url(min(node_id)) + from site_nodes + where object_id = (select package_id + from forums_forums + where forums_forums.forum_id = :forum_id) + + + + + + select site_node__url(min(node_id)) + from site_nodes + where object_id = (select package_id + from forums_forums + where forums_forums.forum_id = :forum_id) + + + + + + select subject, content, format + from forums_messages + where message_id=:message_id or (tree_sortkey between tree_left(:tree_sortkey) and tree_right(:tree_sortkey)) + and forum_id=:forum_id + order by tree_sortkey + + + + Index: openacs-4/contrib/packages/forums/tcl/forums-sc-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forums-sc-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forums-sc-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,177 @@ +ad_library { + + Forums Library - Search Service Contracts + + @creation-date 2002-08-07 + @author Dave Bauer + @cvs-id $Id: forums-sc-procs.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ +} + +namespace eval forum::message {} + +ad_proc -private forum::message::datasource { message_id } { + @param message_id + @author dave@thedesignexperience.org + @creation_date 2002-08-07 + + returns a datasource for the search package + this is the content that will be indexed by the full text + search engine. + + We expect message_id to be a root message of a thread only, + and return the text of all the messages below + +} { + + # If there is no connection than this proc is called from the + # search indexer. In that case we set the locale to the + # system-wide default locale, since locale is needed for some part + # of the message formatting. + if { ![ad_conn isconnected] } { + ad_conn -set locale [lang::system::site_wide_locale] + } + + forum::message::get -message_id $message_id -array message + + if { ![empty_string_p $message(parent_id)] } { + ns_log Notice "forum::message::datasource was called with a message_id that has a parent - skipping: $message_id" + return {object_id {} name {} charter {} mime {} storage_type {}} + } + + set tree_sortkey $message(tree_sortkey) + set forum_id $message(forum_id) + set combined_content "" + set subjects [list] + lappend subjects $message(subject) + + db_foreach messages "" { + + # include the subject in the text if it is different from the thread's subject + set root_subject $message(subject) + regexp {^(?:Re: )+(.*)$} $subject match subject + + if { [string compare $subject $root_subject] != 0 } { + # different subject + append combined_content "$subject\n\n" + } + + append combined_content [ad_html_text_convert -from $format -to text/plain -- $content] + + # In case this text is not only used for indexing but also for display, beautify it + append combined_content "\n\n" + } + + return [list object_id $message(message_id) \ + title $message(subject) \ + content $combined_content \ + keywords {} \ + storage_type text \ + mime text/plain ] +} + +ad_proc -private forum::message::url { message_id } { + @param message_id + @author dave@thedesignexperience.org + @creation_date 2002-08-07 + + returns a url for a message to the search package + +} { + forum::message::get -message_id $message_id -array message + set forum_id $message(forum_id) + + return "[ad_url][db_string select_forums_package_url {}]message-view?message_id=$message_id" +} + + + +namespace eval forum::forum {} + +ad_proc -private forum::forum::datasource { + forum_id +} { + Datasource for the FtsContentProvider contract. + + @param forum_id + + @author Jeff Davis davis@xarg.net + @creation_date 2004-04-01 +} { + if {![db_0or1row datasource { + select + forum_id as object_id, + name as title, + charter as content, + 'text/plain' as mime, + 'text' as storage_type, + '' as keywords + from forums_forums + where forum_id = :forum_id + } -column_array datasource]} { + return {object_id {} name {} charter {} mime {} storage_type {}} + } + + return [array get datasource] +} + +ad_proc -private forum::forum::url { + forum_id +} { + url method for the FtsContentProvider contract + + @param forum_id + + @author Jeff Davis davis@xarg.net + @creation_date 2004-04-01 +} { + return "[ad_url][db_string select_forums_package_url {}]forum-view?forum_id=$forum_id" +} + + +namespace eval forum::sc {} + +ad_proc -private forum::sc::register_implementations {} { + Register the forum_forum and forum_message content type fts contract +} { + db_transaction { + forum::sc::register_forum_fts_impl + forum::sc::register_message_fts_impl + } +} + +ad_proc -private forum::sc::unregister_implementations {} { + db_transaction { + acs_sc::impl::delete -contract_name FtsContentProvider -impl_name forum_message + acs_sc::impl::delete -contract_name FtsContentProvider -impl_name forum_forum + } +} + +ad_proc -private forum::sc::register_forum_fts_impl {} { + set spec { + name "forums_forum" + aliases { + datasource forum::forum::datasource + url forum::forum::url + } + contract_name FtsContentProvider + owner forums + } + + acs_sc::impl::new_from_spec -spec $spec +} + + +ad_proc -private forum::sc::register_message_fts_impl {} { + set spec { + name "forums_message" + aliases { + datasource forum::message::datasource + url forum::message::url + } + contract_name FtsContentProvider + owner forums + } + + acs_sc::impl::new_from_spec -spec $spec +} + Index: openacs-4/contrib/packages/forums/tcl/forums-security-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/forums-security-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/forums-security-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,161 @@ +ad_library { + + Forums Security Library + + @creation-date 2002-05-25 + @author Ben Adida + @cvs-id $Id: forums-security-procs.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} + +namespace eval forum::security { + + ad_proc -private do_abort {} { + do an abort if security violation + } { + if { [ad_conn user_id] == 0 } { + ad_redirect_for_registration + } else { + ad_returnredirect "not-allowed" + } + ad_script_abort + } + + ad_proc -public can_read_forum_p { + {-user_id ""} + {-forum_id:required} + } { + return [permission::permission_p -party_id $user_id -object_id $forum_id -privilege read] + } + + ad_proc -public require_read_forum { + {-user_id ""} + {-forum_id:required} + } { + if {![can_read_forum_p -user_id $user_id -forum_id $forum_id]} { + do_abort + } + } + + ad_proc -public can_read_message_p { + {-user_id ""} + {-message_id:required} + } { + # if the user is a guest, they can't see any forum messages at all + if { ![acs_privacy::user_can_read_private_data_p -user_id $user_id -object_id [ad_conn package_id]] } { + return 0 + } else { + return [permission::permission_p -party_id $user_id -object_id $message_id -privilege read] + } + } + + ad_proc -public require_read_message { + {-user_id ""} + {-message_id:required} + } { + if {![can_read_message_p -user_id $user_id -message_id $message_id]} { + do_abort + } + } + + ad_proc -public can_post_forum_p { + {-user_id ""} + {-forum_id:required} + } { + return [permission::permission_p -party_id $user_id -object_id $forum_id -privilege create] + } + + ad_proc -public require_post_forum { + {-user_id ""} + {-forum_id:required} + } { + if {![can_post_forum_p -user_id $user_id -forum_id $forum_id]} { + do_abort + } + } + + ad_proc -public can_post_message_p { + {-user_id ""} + {-message_id:required} + } { + return [permission::permission_p -party_id $user_id -object_id $message_id -privilege write] + } + + ad_proc -public require_post_message { + {-user_id ""} + {-message_id:required} + } { + if {![can_post_message_p -user_id $user_id -message_id $message_id]} { + do_abort + } + } + + ad_proc -public can_moderate_forum_p { + {-user_id ""} + {-forum_id:required} + } { + return [permission::permission_p -party_id $user_id -object_id $forum_id -privilege forum_moderate] + } + + ad_proc -public require_moderate_forum { + {-user_id ""} + {-forum_id:required} + } { + if {![can_moderate_forum_p -user_id $user_id -forum_id $forum_id]} { + do_abort + } + } + + ad_proc -public can_moderate_message_p { + {-user_id ""} + {-message_id:required} + } { + return [permission::permission_p -party_id $user_id -object_id $message_id -privilege forum_moderate] + } + + ad_proc -public require_moderate_message { + {-user_id ""} + {-message_id:required} + } { + if {![can_moderate_message_p -user_id $user_id -message_id $message_id]} { + do_abort + } + } + + ad_proc -public can_admin_forum_p { + {-user_id ""} + {-forum_id:required} + } { + return [permission::permission_p -party_id $user_id -object_id $forum_id -privilege forum_moderate] + } + + ad_proc -public require_admin_forum { + {-user_id ""} + {-forum_id:required} + } { + if {![can_admin_forum_p -user_id $user_id -forum_id $forum_id]} { + do_abort + } + } + + ad_proc -public permissions { + {-forum_id:required} + array_name + } { + upvar $array_name array + + array set array [list admin_p [forum::security::can_admin_forum_p -forum_id $forum_id]] + + if { !$array(admin_p) } { + array set array [list moderate_p [forum::security::can_moderate_forum_p -forum_id $forum_id]] + if { !$array(moderate_p) } { + array set array [list post_p [expr { [ad_conn user_id] == 0 || [forum::security::can_post_forum_p -forum_id $forum_id] }]] + } else { + array set array [list post_p 1] + } + } else { + array set array [list moderate_p 1] + array set array [list post_p 1] + } + } +} Index: openacs-4/contrib/packages/forums/tcl/messages-format-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/messages-format-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/messages-format-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,52 @@ +ad_library { + message formatting procs +} + +namespace eval forum::format { + + ad_proc -public reply_subject { parent_subject } { + + Generates a subject string for a reply to an existing message. + + } { + set subject "[_ forums.Re] $parent_subject" + + # trim multiple leading Re: + regsub "^(\s*Re:\s*)*" $subject {Re: } subject + + return $subject + } + + ad_proc emoticons { + {-content:required} + } { + Convert smileys (emoticons) to img references. It constructs a relative + image reference to graphics/imagename.gif, so it will only work when + used from pages that are directly under the forums/www/ directory. + +

+ + If you change the images make sure to also adapt the image sizes in + the img tag that gets constructed here. + } { + set emoticons_map [list] + + # if you change this list, consider changing + # www/doc/emoticons.adp as well + foreach { emoticon image } { + ":-)" "smile" + ";-)" "wink" + ":-D" "bigsmile" + "8-)" "smile8" + ":-(" "sad" + ";-(" "cry" + ":-O" "scream" + ":-/" "think" + } { + lappend emoticons_map $emoticon + lappend emoticons_map "\"$emoticon\"" + } + return [string map $emoticons_map $content] + } + +} Index: openacs-4/contrib/packages/forums/tcl/messages-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/messages-procs-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/messages-procs-oracle.xql 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,66 @@ + + + + oracle8.1.6 + + + + select forums_messages.*, + 0 as n_attachments, + person.name(forums_messages.user_id) as user_name, + party.email(forums_messages.user_id) as user_email, + forums_forum.name(forums_messages.forum_id) as forum_name, + forums_message.root_message_id(forums_messages.message_id) as root_message_id, + (select fm2.subject + from forums_messages fm2 + where fm2.message_id = forums_message.root_message_id(forums_messages.message_id)) as root_subject, + to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi + from forums_messages + where forums_messages.message_id = :message_id + + + + + + select forums_messages.*, + (select count(*) from attachments where object_id= message_id) as n_attachments, + person.name(forums_messages.user_id) as user_name, + party.email(forums_messages.user_id) as user_email, + forums_forum.name(forums_messages.forum_id) as forum_name, + forums_message.root_message_id(forums_messages.message_id) as root_message_id, + (select fm2.subject + from forums_messages fm2 + where fm2.message_id = forums_message.root_message_id(forums_messages.message_id)) as root_subject, + to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi + from forums_messages + where forums_messages.message_id = :message_id + + + + + + select site_node.url(node_id) + from site_nodes + where object_id = (select package_id + from forums_forums + where forums_forums.forum_id = :forum_id) + + + + + + declare begin + forums_message.thread_close(:message_id); + end; + + + + + + declare begin + forums_message.thread_open(:message_id); + end; + + + + Index: openacs-4/contrib/packages/forums/tcl/messages-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/messages-procs-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/messages-procs-postgresql.xql 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,62 @@ + + + + postgresql7.1 + + + + select forums_messages.*, + tree_level(forums_messages.tree_sortkey) as tree_level, + person__name(forums_messages.user_id) as user_name, + party__email(forums_messages.user_id) as user_email, + forums_forum__name(forums_messages.forum_id) as forum_name, + forums_message__root_message_id(forums_messages.message_id) as root_message_id, + (select fm2.subject + from forums_messages fm2 + where fm2.message_id = forums_message__root_message_id(forums_messages.message_id)) as root_subject, + to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi + from forums_messages + where forums_messages.message_id= :message_id + + + + + + select forums_messages.*, + (select count(*) from attachments where object_id= message_id) as n_attachments, + person__name(forums_messages.user_id) as user_name, + party__email(forums_messages.user_id) as user_email, + forums_forum__name(forums_messages.forum_id) as forum_name, + forums_message__root_message_id(forums_messages.message_id) as root_message_id, + (select fm2.subject + from forums_messages fm2 + where fm2.message_id = forums_message__root_message_id(forums_messages.message_id)) as root_subject, + to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi + from forums_messages + where forums_messages.message_id= :message_id + + + + + + select site_node__url(node_id) + from site_nodes + where object_id = (select package_id + from forums_forums + where forums_forums.forum_id = :forum_id) + + + + + + select forums_message__thread_close(:message_id); + + + + + + select forums_message__thread_open(:message_id); + + + + Index: openacs-4/contrib/packages/forums/tcl/messages-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/messages-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/messages-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,331 @@ +ad_library { + + Forums Library - for Messages + + @creation-date 2002-05-20 + @author Ben Adida + @cvs-id $Id: messages-procs.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} + +namespace eval forum::message {} + +ad_proc -public forum::message::new { + {-forum_id:required} + {-message_id ""} + {-parent_id ""} + {-subject:required} + {-content:required} + {-format "text/plain"} + {-user_id ""} +} { + create a new message +} { + # If no user_id is provided, we set it + # to the currently logged-in user + if {[empty_string_p $user_id]} { + set user_id [ad_conn user_id] + } + + set original_message_id $message_id + + db_transaction { + + set var_list [list \ + [list forum_id $forum_id] \ + [list message_id $message_id] \ + [list parent_id $parent_id] \ + [list subject $subject] \ + [list content $content] \ + [list format $format] \ + [list user_id $user_id]] + + set message_id [package_instantiate_object -var_list $var_list forums_message] + + get -message_id $message_id -array message + if {[info exists message(state)] && [string equal $message(state) approved]} { + do_notifications -message_id $message_id + } + } on_error { + + db_abort_transaction + + # Check to see if the message with a message_id matching the + # message_id arguement was in the database before calling + # this procedure. If so, the error is due to a double click + # and we should continue without returning an error. + + if {![empty_string_p $original_message_id]} { + # The was a non-null message_id arguement + if {[db_string message_exists_p { *SQL* }]} { + return $message_id + } else { + # OK - it wasn't a simple double-click, so bomb + ad_return_error \ + "OACS Internal Error" \ + "Error in forums::message::new - $errmsg" + } + } + } + + return $message_id +} + +ad_proc -public forum::message::do_notifications { + {-message_id:required} +} { + # Select all the important information + forum::message::get -message_id $message_id -array message + + set forum_id $message(forum_id) + set url "[ad_url][db_string select_forums_package_url {}]" + + set attachments [attachments::get_attachments -object_id $message(message_id)] + + set message_text [ad_html_text_convert -from $message(format) -to text/plain -- $message(content)] + set message_html [ad_html_text_convert -from $message(format) -to text/html -- $message(content)] + + set html_version "" + append html_version "Forum: $message(forum_name)
\n" + append html_version "Thread: $message(root_subject)
\n" + append html_version "Author: $message(user_name)
\n" + append html_version "Posted: $message(posting_date)
\n" + # append html_version "[_ forums.lt_You_may_respond_to_th]
" + append html_version "\n
\n" + append html_version $message_html + append html_version "

" + + if {[llength $attachments] > 0} { + append html_version "Attachments: +

" + + } + + set html_version $html_version + + set text_version "" + append text_version " +Forum: $message(forum_name) +Thread: $message(root_message_id) +Author: $message(user_name) +Posted: $message(posting_date) +---------------------------------- +$message_text +--------------------------------- +To post a reply to this email or view this message go to: +${url}message-view?message_id=$message(root_message_id) + +To view Forum $message(forum_name) go to: +${url}forum-view?forum_id=$message(forum_id) +" + # Do the notification for the forum + notification::new \ + -type_id [notification::type::get_type_id \ + -short_name forums_forum_notif] \ + -object_id $message(forum_id) \ + -response_id $message(message_id) \ + -notif_subject "\[$message(forum_name)\] $message(subject)" \ + -notif_text $text_version \ + -notif_html $html_version + + + # Eventually we need notification for the root message too + notification::new \ + -type_id [notification::type::get_type_id \ + -short_name forums_message_notif] \ + -object_id $message(root_message_id) \ + -response_id $message(message_id) \ + -notif_subject "\[$message(forum_name)\] $message(subject)" \ + -notif_text $text_version \ + -notif_html $html_version +} + +ad_proc -public forum::message::edit { + {-message_id:required} + {-subject:required} + {-content:required} + {-format:required} +} { + Editing a message. There is no versioning here! + This means this function is for admins only! +} { + # do the update + db_dml update_message {} + db_dml update_message_title {} +} + +ad_proc -public forum::message::set_format { + {-message_id:required} + {-format:required} +} { + set whether a message is HTML or not +} { + # Straight update to the DB + db_dml update_message_format +} + +ad_proc -public forum::message::get { + {-message_id:required} + {-array:required} +} { + get the fields for a forum +} { + # Select the info into the upvar'ed Tcl Array + upvar $array row + + set query select_message + + if {[ad_conn isconnected] && [forum::attachments_enabled_p]} { + set query select_message_with_attachment + } + + if {![db_0or1row $query {} -column_array row]} { + if {[array exists row]} { + array unset row + } + } else { + # Convert to user's date/time format + set row(posting_date_ansi) [lc_time_system_to_conn $row(posting_date_ansi)] + set row(posting_date_pretty) [lc_time_fmt $row(posting_date_ansi) "%x %X"] + } +} + +ad_proc -private forum::message::set_state { + {-message_id:required} + {-state:required} +} { + Set the new state for a message + Usually used for approval +} { + set var_list [list \ + [list message_id $message_id] \ + [list state $state]] + package_exec_plsql -var_list $var_list forums_message set_state +} + +ad_proc -public forum::message::reject { + {-message_id:required} +} { + Reject a message +} { + set_state -message_id $message_id -state rejected +} + +ad_proc -public forum::message::approve { + {-message_id:required} +} { + approve a message +} { + db_transaction { + set_state -message_id $message_id -state approved + do_notifications -message_id $message_id + } +} + +ad_proc -public forum::message::delete { + {-message_id:required} +} { + delete a message and obviously all of its descendents +} { + db_transaction { + # Remove the notifications + notification::request::delete_all -object_id $message_id + + # Remove the message + set var_list [list [list message_id $message_id]] + package_exec_plsql -var_list $var_list forums_message delete_thread + } +} + +ad_proc -public forum::message::close { + {-message_id:required} +} { + close a thread + This is not exactly a cheap operation if the thread is long +} { + db_exec_plsql thread_close {} +} + +ad_proc -public forum::message::open { + {-message_id:required} +} { + reopen a thread + This is not exactly a cheap operation if the thread is long +} { + db_exec_plsql thread_open {} +} + +ad_proc -public forum::message::get_attachments { + {-message_id:required} +} { + get the attachments for a message +} { + # If attachments aren't enabled, then we stop + if {![forum::attachments_enabled_p]} { + return [list] + } + + return [attachments::get_attachments -object_id $message_id] +} + +ad_proc -public forum::message::subject_sort_filter { + -forum_id:required + -order_by:required +} { + Return a piece of HTML for toggling the sort order of threads (subjects) + in a forum. The user can either sort by the first postings in subjects + (the creation date of the subjects) or the last one. + + @author Peter Marklund +} { + set subject_label "[_ forums.lt_First_post_in_subject]" + set child_label "[_ forums.Last_post_in_subject]" + set new_order_by [ad_decode $order_by posting_date last_child_post posting_date] + + set export_vars [ad_export_vars -override [list [list order_by $new_order_by]] {order_by forum_id}] + set toggle_url "[ad_conn url]?${export_vars}" + if { [string equal $order_by posting_date] } { + # subject selected + set subject_link "$subject_label" + set child_link "$child_label" + } else { + # child selected + set subject_link "$subject_label" + set child_link "$child_label" + } + set sort_filter "$subject_link | $child_link" + + return $sort_filter +} + +ad_proc -public forum::message::initial_message { + {-forum_id {}} + {-parent {}} + {-message:required} +} { + Create an array with values initialised for a new message. +} { + upvar $message init_msg + + if { [empty_string_p $forum_id] && [empty_string_p $parent] } { + return -code error [_ forums.lt_You_either_have_to] + } + + if { ![empty_string_p $parent] } { + upvar $parent parent_msg + + set init_msg(parent_id) $parent_msg(message_id) + set init_msg(forum_id) $parent_msg(forum_id) + set init_msg(subject) \ + [forum::format::reply_subject $parent_msg(subject)] + } else { + set init_msg(forum_id) $forum_id + set init_msg(parent_id) "" + } +} Index: openacs-4/contrib/packages/forums/tcl/messages-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/Attic/messages-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/messages-procs.xql 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,38 @@ + + + + + + update forums_messages + set format = :format + where message_id = :message_id + + + + + + update acs_objects + set title = :subject + where object_id = :message_id and object_type = 'forums_message' + + + + + + update forums_messages + set subject = :subject, + content = :content, + format = :format + where message_id = :message_id + + + + + + select count(message_id) + from forums_messages + where message_id = :message_id + + + + Index: openacs-4/contrib/packages/forums/tcl/test/forums-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/test/Attic/forums-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/test/forums-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,303 @@ +ad_library { + Automated tests. + + @author Simon Carstensen + @creation-date 15 November 2003 + @author Gerardo Morales + @author Mounir Lallali + @cvs-id $Id: forums-procs.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ +} + +aa_register_case -cats {api smoke} forum_new { + Test the forum::new proc. +} { + + aa_run_with_teardown \ + -rollback \ + -test_code { + + # Create forum + set forum_id [forum::new \ + -name "foo" \ + -package_id [ad_conn package_id]] + + set success_p [db_string success_p { + select 1 from forums_forums where forum_id = :forum_id + } -default "0"] + + aa_equals "forum was created succesfully" $success_p 1 + } +} + +aa_register_case -cats {api smoke} forum_message_new { + Test the forum::message::new proc. +} { + + aa_run_with_teardown \ + -rollback \ + -test_code { + + # Create forum + set forum_id [forum::new \ + -name "foo" \ + -package_id [ad_conn package_id]] + + # Create message + set message_id [forum::message::new \ + -forum_id $forum_id \ + -subject "foo" \ + -content "foo"] + + set success_p [db_string success_p { + select 1 from forums_messages where message_id = :message_id + } -default "0"] + + aa_equals "message was created succesfully" $success_p 1 + } +} + +aa_register_case -cats {db smoke} forum_count_test { + Test the thread count and reply count tracking code. +} { + + aa_run_with_teardown \ + -rollback \ + -test_code { + + # Create open forum + set forum_id [forum::new \ + -name foo \ + -package_id [ad_conn package_id]] + + forum::get -forum_id $forum_id -array forum + aa_equals "New forum has zero approved threads" $forum(approved_thread_count) 0 + aa_equals "New forum has zero threads" $forum(thread_count) 0 + + # Create message + set message_id [forum::message::new \ + -forum_id $forum_id \ + -subject foo \ + -content foo] + + forum::get -forum_id $forum_id -array forum + aa_equals "After post forum has one approved thread" $forum(approved_thread_count) 1 + aa_equals "After post forum has one threads" $forum(thread_count) 1 + + forum::message::get -message_id $message_id -array message + aa_equals "New post has zero approved replies" $message(approved_reply_count) 0 + aa_equals "New post has zero threads" $message(reply_count) 0 + + set reply_id [forum::message::new \ + -forum_id $forum_id \ + -parent_id $message_id \ + -subject foo \ + -content foo] + + forum::get -forum_id $forum_id -array forum + aa_equals "After reply forum has one approved thread" $forum(approved_thread_count) 1 + aa_equals "After reply forum has one thread" $forum(thread_count) 1 + + forum::message::get -message_id $message_id -array message + aa_equals "After reply post has one approved replies" $message(approved_reply_count) 1 + aa_equals "After reply post has one reply" $message(reply_count) 1 + + # Create moderated forum + set forum_id [forum::new \ + -name bar \ + -posting_policy moderated \ + -package_id [ad_conn package_id]] + + # Create message + set message_id [forum::message::new \ + -forum_id $forum_id \ + -subject "foo" \ + -content "foo"] + + forum::get -forum_id $forum_id -array forum + aa_equals "After post moderated forum has zero approved threads" $forum(approved_thread_count) 0 + aa_equals "After post moderated forum has one thread" $forum(thread_count) 1 + + set reply_id [forum::message::new \ + -forum_id $forum_id \ + -parent_id $message_id \ + -subject "foo" \ + -content "foo"] + + forum::message::get -message_id $message_id -array message + aa_equals "After reply moderated post has zero approved replies" $message(approved_reply_count) 0 + aa_equals "After reply moderated post has one reply" $message(reply_count) 1 + + forum::message::set_state -message_id $message_id -state approved + + forum::get -forum_id $forum_id -array forum + aa_equals "After approval moderated forum has one approved thread" $forum(approved_thread_count) 1 + aa_equals "After approval moderated forum has one thread" $forum(thread_count) 1 + + forum::message::set_state -message_id $reply_id -state approved + + forum::message::get -message_id $message_id -array message + aa_equals "After reply approval post has one approved reply" $message(approved_reply_count) 1 + aa_equals "After reply approval post has one reply" $message(reply_count) 1 + + forum::message::delete -message_id $message_id + + forum::get -forum_id $forum_id -array forum + aa_equals "After deletion moderated forum has zero approved threads" $forum(approved_thread_count) 0 + aa_equals "After deletion moderated forum has zero threads" $forum(thread_count) 0 + } +} + + +aa_register_case -cats {web smoke} -libraries tclwebtest web_forum_new { + Testing the creation of a forum via web +} { + + aa_run_with_teardown -test_code { + + tclwebtest::cookies clear + + # Login user + array set user_info [twt::user::create -admin] + twt::user::login $user_info(email) $user_info(password) + + # Create a new forum + set name [ad_generate_random_string] + set response [forums::twt::new "$name"] + aa_display_result -response $response -explanation {Webtest for the creation of a new Forum} + + twt::user::logout + } + +} + +aa_register_case -cats {web smoke} -libraries tclwebtest web_forum_edit { + Testing the edition of an existing forum +} { + + aa_run_with_teardown -test_code { + + tclwebtest::cookies clear + + # Login user + array set user_info [twt::user::create -admin] + twt::user::login $user_info(email) $user_info(password) + + # Create a forum + set name [ad_generate_random_string] + forums::twt::new "$name" + + # Edit the created forum + set response [forums::twt::edit "$name"] + aa_display_result -response $response -explanation {Webtest for the edition of a forum} + + twt::user::logout + } +} + +aa_register_case -cats {web smoke} -libraries tclwebtest web_message_new { + Posting a new message to an existing forum +} { + + + aa_run_with_teardown -test_code { + + tclwebtest::cookies clear + + # Login user + array set user_info [twt::user::create -admin] + twt::user::login $user_info(email) $user_info(password) + + # Create a forum + set name [ad_generate_random_string] + forums::twt::new "$name" + + # Post a message in the created forum + set subject [ad_generate_random_string] + set response [forums::twt::new_post "$name" "$subject"] + aa_display_result -response $response -explanation {Webtest for posting a message in a forum} + + twt::user::logout + } +} + +aa_register_case -cats {web smoke} -libraries tclwebtest web_message_edit { + Editing a message of a forum +} { + + aa_run_with_teardown -test_code { + + tclwebtest::cookies clear + + # Login user + array set user_info [twt::user::create -admin] + twt::user::login $user_info(email) $user_info(password) + + # Create a forum + set name [ad_generate_random_string] + forums::twt::new "$name" + + # Post a message in the created forum + set subject [ad_generate_random_string] + forums::twt::new_post "$name" "$subject" + + # Edit the posted message + set response [forums::twt::edit_post "$name" "$subject"] + aa_display_result -response $response -explanation {Webtest for editing the message of a forum} + + twt::user::logout + } +} + +aa_register_case -cats {web smoke} -libraries tclwebtest web_message_reply { + Post a reply a message in the forum +} { + aa_run_with_teardown -test_code { + + tclwebtest::cookies clear + + # Login user + array set user_info [twt::user::create -admin] + twt::user::login $user_info(email) $user_info(password) + + # Create a forum + set name [ad_generate_random_string] + forums::twt::new "$name" + + # Post a message in the created forum + set subject [ad_generate_random_string] + forums::twt::new_post "$name" "$subject" + + # Edit the posted message + set response [forums::twt::reply_msg "$name" "$subject"] + aa_display_result -response $response -explanation {Webtest for posting a reply to a msg in the forum} + + twt::user::logout + } +} + +aa_register_case -cats {web smoke} -libraries tclwebtest web_message_delete { + Delete a message in the forum +} { + aa_run_with_teardown -test_code { + + tclwebtest::cookies clear + + # Login user + array set user_info [twt::user::create -admin] + twt::user::login $user_info(email) $user_info(password) + + # Create a forum + set name [ad_generate_random_string] + forums::twt::new "$name" + + # Post a message in the created forum + set subject [ad_generate_random_string] + forums::twt::new_post "$name" "$subject" + + # Edit the posted message + set response [forums::twt::delete_post "$name" "$subject"] + aa_display_result -response $response -explanation {Webtest for deleting a message posted in the forum} + + twt::user::logout + } +} \ No newline at end of file Index: openacs-4/contrib/packages/forums/tcl/test/tclwebtest-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/tcl/test/Attic/tclwebtest-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/tcl/test/tclwebtest-procs.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,273 @@ +ad_library { + Automated tests. + @author Gerardo Morales (gerardo.morales@gmail.net) + @author Mounir Lallali + + @creation-date 14 June 2005 + +} + +namespace eval forums::twt { + + ad_proc new { name } { + + set response 0 + + # The Faq Admin page url + set forum_admin_page [aa_get_first_url -package_key forums] + ::twt::do_request $forum_admin_page + + # Seting the charter that would be used in the forum creation form + set charter "[ad_generate_random_string] [ad_generate_random_string]" + + # Follows the link of New Forum + tclwebtest::link follow "New Forum" + tclwebtest::form find ~n "forum" + tclwebtest::field find ~n "name" + tclwebtest::field fill "$name" + tclwebtest::field find ~n "charter" + tclwebtest::field fill "$charter" + tclwebtest::form submit + aa_log "Forum $name just to be created" + + set response_url [tclwebtest::response url] + aa_log $forum_admin_page + + if {[string first $forum_admin_page $response_url]!=-1} { + + if { [catch {tclwebtest::link find $name} testerror1] ||[catch {tclwebtest::assert text $charter} testerror2 ] } { + aa_error "The forum $name was not created. The forum name or the charter was not founded in the admin page of forums" + } else { + aa_log "The forum $name was succesfully created" + set response 1 + } + + } else { + aa_error "forums::twt::new failed, bad response url : $response_url" + } + + return $response + } + + ad_proc edit { name } { + + set response 0 + + # Call to the faq admin page + set forum_admin_page [aa_get_first_url -package_key forums] + ::twt::do_request $forum_admin_page + + # Follows the link of administration and then admin the forum + tclwebtest::link follow $name + tclwebtest::link follow "Administer" + aa_log "The data of the $name forum will be changed" + + set charter "[ad_generate_random_string] [ad_generate_random_string 8]" + + # Enter the new data and submit + tclwebtest::form find ~n "forum" + tclwebtest::field find ~n "name" + tclwebtest::field fill "Edited $name" + tclwebtest::field find ~n "charter" + tclwebtest::field fill "Edited $charter" + tclwebtest::form submit + aa_log "Form Submited" + + # Testing the edition + set response_url [tclwebtest::response url] + + if {[string first "forum-view" $response_url]!=-1 && [string first $forum_admin_page $response_url]!=-1 } { + + ::twt::do_request $forum_admin_page + + if { [catch {tclwebtest::link find "Edited $name"} testerror1] ||[catch {tclwebtest::assert text "$charter"} testerror2 ] } { + aa_error "The forum $name was not Edited. The forum name or the charter was not founded in the admin page of forums" + } else { + aa_log "The forum $name was succesfully edited, new name Edited $name" + set response 1 + } + + } else { + aa_error "forums::twt::edit failed, bad response url : $response_url" + } + + return $response + } + + ad_proc new_post {name subject} { + + set response 0 + # Seting the Subject and Body of the new post + set msgb "[ad_generate_random_string] [ad_generate_random_string 20]" + + # Call to the faq admin page + set forum_admin_page [aa_get_first_url -package_key forums] + ::twt::do_request $forum_admin_page + + # Follows the link of administration and then the Post a new message + tclwebtest::link follow $name + tclwebtest::link follow "Post a New Message" + + # Enter the data and submit + tclwebtest::form find ~n "message" + tclwebtest::field find ~n "subject" + tclwebtest::field fill "$subject" + tclwebtest::field find ~n "message_body" + tclwebtest::field fill "$msgb" + tclwebtest::form submit + aa_log "New message form submited" + + set response_url [tclwebtest::response url] + + if {[string first "message-view" $response_url]!=-1 && [string first $forum_admin_page $response_url]!=-1 } { + + tclwebtest::link follow "$name" + + # Testing the message + if {[catch {tclwebtest::link follow "$subject"}]} { + aa_error "The messaje was not posted" + } + + if { [catch {tclwebtest::assert text "$msgb"} testerror2 ] } { + aa_error "The body of the message was not correctly posted" + } else { + aa_log "The message was succesfully posted" + set response 1 + } + + } else { + aa_error "forums::twt::new_post failed, bad response url : $response_url" + } + + return $response + } + + ad_proc edit_post {name subject} { + + set response 0 + + # Seting the new body of the message + set msgb2 "[ad_generate_random_string] [ad_generate_random_string 20]" + + # Call to the faq admin page + set forum_admin_page [aa_get_first_url -package_key forums] + ::twt::do_request $forum_admin_page + + + # Follows the link of administration and then Edit the posted message + tclwebtest::link follow $name + tclwebtest::link follow $subject + tclwebtest::link follow Edit + + # Fill and submit the form for editing + tclwebtest::form find ~n "message" + tclwebtest::field find ~n "subject" + tclwebtest::field fill "Edited $subject" + tclwebtest::field find ~n "message_body" + tclwebtest::field fill "$msgb2" + tclwebtest::form submit + aa_log "Edit message form submited" + + set response_url [tclwebtest::response url] + + if {[string first "message-view" $response_url]!=-1 && [string first $forum_admin_page $response_url]!=-1 } { + + # Testing if the new text is in the message + if {[catch {tclwebtest::link follow "Edited $subject"}]} { + aa_error "The messaje was not edited" + } + + if { [catch {tclwebtest::assert text "$msgb2"} testerror2 ] } { + aa_error "The body of the message was not correctly edited" + } else { + aa_log "The message $subject of the forum $name was succesfully edited" + set response 1 + } + + } else { + aa_error "forums::twt::edit_post failed, bad response url : $response_url" + } + + return $response + } + + ad_proc delete_post {name subject} { + + set response 0 + # Call to the faq admin page + set forum_admin_page [aa_get_first_url -package_key forums] + ::twt::do_request $forum_admin_page + + # Follows the link of administration and then Edit the posted message + tclwebtest::link follow $name + tclwebtest::link follow $subject + tclwebtest::link follow Delete + tclwebtest::link follow Yes + + set response_url [tclwebtest::response url] + + # Testing if the the message is not in the forum + if {[string first "forum-view" $response_url]!=-1 && [string first $forum_admin_page $response_url]!=-1 } { + + if {[catch {tclwebtest::link follow "Edited $subject"}]} { + aa_log "The message $subject was succesfully deleted in the forum $name" + set response 1 + } else { + aa_error "The message $subject of the forum $name was not deleted" + } + + } else { + aa_error "forums::twt::delete_post failed, bad response url : $response_url" + } + + return $response + } + + ad_proc reply_msg {name subject} { + + set response 0 + + # Seting the new body of the message + set msgb_reply "[ad_generate_random_string] [ad_generate_random_string 20]" + + # Call to the faq admin page + set forum_admin_page [aa_get_first_url -package_key forums] + ::twt::do_request $forum_admin_page + + + # Follows the link of administration and then Edit the posted message + tclwebtest::link follow $name + tclwebtest::link follow $subject + tclwebtest::link follow "Post a Reply" + + # Fill and submit the form for editing + tclwebtest::form find ~n "message" + tclwebtest::field find ~n "message_body" + tclwebtest::field fill "$msgb_reply" + tclwebtest::form submit + aa_log "Reply message submitted" + + set response_url [tclwebtest::response url] + + # Testing if the new text is in the message + if {[string first "message-view" $response_url]!=-1 && [string first $forum_admin_page $response_url]!=-1 } { + + if {[catch {tclwebtest::link find "Re: $subject"}]} { + aa_error "The reply message was not posted" + } + + if { [catch {tclwebtest::assert text "$msgb_reply"} testerror2 ] } { + aa_error "The body of the replyed message was not correctly posted" + } else { + aa_log "The reply message to $subject of the forum $name was succesfully posted" + set response 1 + } + + } else { + aa_error "forums::twt::reply_msg failed, bad response url : $response_url" + } + + return $response + } + +} \ No newline at end of file Index: openacs-4/contrib/packages/forums/www/forum-view.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/forum-view.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/forum-view.adp 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,20 @@ + + @page_title;noquote@ + @context;noquote@ + @forum_id;noquote@ + + + + + + @ah_sources;noquote@ + + + +@notification_chunk;noquote@ +

+ + +

+ Back +
Index: openacs-4/contrib/packages/forums/www/forum-view.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/forum-view.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/forum-view.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,80 @@ +ad_page_contract { + + one forum view + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-24 + @cvs-id $Id: forum-view.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} -query { + forum_id:integer,notnull + {expand:integer,multiple ""} + {orderby "last_child_post,desc"} + {viewby ""} + page:optional +} + + +# Get forum data +if {[catch {forum::get -forum_id $forum_id -array forum} errMsg]} { + if {[string equal $::errorCode NOT_FOUND]} { + ns_returnnotfound + ad_script_abort + } + error $errMsg $::errorInfo $::errorCode +} + +# If disabled! +if {$forum(enabled_p) != "t"} { + ad_returnredirect "./" + ad_script_abort +} + +forum::security::require_read_forum -forum_id $forum_id +forum::security::permissions -forum_id $forum_id permissions + +#it is confusing to provide a moderate link for non-moderated forums. +if { $forum(posting_policy) != "moderated" } { + set permissions(moderate_p) 0 +} + +# determine if we want to enable ajax and dhtml effects +set ajax_effects [parameter::get -parameter "EnableAjax"] + +set ah_sources [ah::js_sources] + +# get the colors from the params +set table_border_color [parameter::get -parameter table_border_color] +set table_bgcolor [parameter::get -parameter table_bgcolor] +set table_other_bgcolor [parameter::get -parameter table_other_bgcolor] + +set admin_url [export_vars -base "admin/forum-edit" { forum_id {return_url [ad_return_url]}}] +set moderate_url [export_vars -base "moderate/forum" { forum_id }] +set post_url [export_vars -base "message-post" { forum_id }] + +# Create a search form and action when used +set searchbox_p [parameter::get -parameter ForumsSearchBoxP -default 1] +if {$searchbox_p} { + form create search -action search + forums::form::search search + + if {[form is_request search]} { + element set_properties search forum_id -value $forum_id + } +} +# Need to quote forum(name) since it is noquoted on display as part of an +# HTML fragment. +set notification_chunk [notification::display::request_widget \ + -type forums_forum_notif \ + -object_id $forum_id \ + -pretty_name $forum(name) \ + -url [ad_conn url]?forum_id=$forum_id \ +] + +set page_title "[_ forums.Forum_1] $forum(name)" +set context [list [ad_quotehtml $forum(name)]] + +set type_id [notification::type::get_type_id -short_name forums_forum_notif] +set notification_count [notification::request::request_count \ + -type_id $type_id \ + -object_id $forum_id] \ No newline at end of file Index: openacs-4/contrib/packages/forums/www/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/index.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/index.adp 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,20 @@ + +#forums.Forums# +@context;noquote@ + + + + + + + + + + + + + + + + + Index: openacs-4/contrib/packages/forums/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/index.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/index.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,22 @@ +ad_page_contract { + + top level list of forums + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-24 + @cvs-id $Id: index.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} + +set package_id [ad_conn package_id] +set user_id [ad_conn user_id] +set admin_p [permission::permission_p -party_id $user_id -object_id $package_id -privilege admin] +set searchbox_p [parameter::get -parameter ForumsSearchBoxP -package_id $package_id -default 1] + +# Create a search form and action when used +if {$searchbox_p} { + form create search -action search + forums::form::search search +} + +set context {} Index: openacs-4/contrib/packages/forums/www/message-email.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/message-email.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/message-email.adp 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,19 @@ + + #forums.Email_Message# @message.forum_name;noquote@ - @message.subject;noquote@ + @context;noquote@ + + + + + + + + + +

#forums.lt_Email_a_copy_of_the_f#

+ +
+ +
+ + Index: openacs-4/contrib/packages/forums/www/message-email.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/message-email.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/message-email.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,56 @@ +ad_page_contract { + + Forward a message to a friend + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-28 + @cvs-id $Id: message-email.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} { + message_id:integer,notnull +} + +forum::security::require_read_message -message_id $message_id + +# Get the message information +forum::message::get -message_id $message_id -array message +set message(tree_level) 0 + +form create message + +element create message message_id \ + -label [_ forums.Message_ID] \ + -datatype integer \ + -widget hidden + +forums::form::forward_message message + +if {[form is_valid message]} { + template::form get_values message message_id to_email subject pre_body + + # Create the email body + set email_body [forum::email::create_forward_email -pre_body $pre_body message] + + # Send the email + acs_mail_lite::send -to_addr $to_email \ + -from_addr [cc_email_from_party [ad_conn user_id]] \ + -subject $subject \ + -body $email_body + + ad_returnredirect "message-view?message_id=$message_id" + ad_script_abort +} + +if {[template::form is_request message]} { + element set_properties message message_id -value $message_id + element set_properties message subject -value $message(subject) +} + +set context [list [list "./forum-view?forum_id=$message(forum_id)" "$message(forum_name)"]] +if {![empty_string_p $message(parent_id)]} { + lappend context [list "./message-view?message_id=$message(root_message_id)" "[_ forums.Entire_Thread]"] +} +lappend context [list "./message-view?message_id=$message(message_id)" "$message(subject)"] +lappend context [_ forums.Email_to_a_friend] + +ad_return_template Index: openacs-4/contrib/packages/forums/www/message-post-confirm.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/message-post-confirm.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/message-post-confirm.adp 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,16 @@ + +#forums.Confirm_Post_to_Forum# @forum.name;noquote@ +@context;noquote@ + + + + + + + + + + Index: openacs-4/contrib/packages/forums/www/message-post.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/message-post.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/message-post.adp 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,18 @@ + +#forums.Post_to_Forum# @forum.name;noquote@ +@context;noquote@ +message.subject + + + + + + + + + + + Index: openacs-4/contrib/packages/forums/www/message-post.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/message-post.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/message-post.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,85 @@ +ad_page_contract { + + Form to create message and insert it + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-25 + @cvs-id $Id: message-post.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} -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] + } + } +} + +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 "" +} + +set user_id [auth::refresh_login] + +############################## +# 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 + + 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 + + # see if they're allowed to add to this thread + forum::security::require_post_message -message_id $parent_id + + forum::get -forum_id $parent_message(forum_id) -array forum +} + +############################## +# 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])] + +set attachments_enabled_p [forum::attachments_enabled_p] + +############################## +# Template variables +# + +if {![string equal [template::form::get_button message] "preview"]} { + set context [list [list "./forum-view?forum_id=$forum_id" [ad_quotehtml $forum(name)]]] + + 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]" + + ad_return_template "message-post-confirm" +} + + Index: openacs-4/contrib/packages/forums/www/message-view.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/message-view.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/message-view.adp 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,62 @@ + + #forums.Thread_title# + @context;noquote@ + @message_id@ + + + + + + + + + + + + @dynamic_script;noquote@ + + + + +
+ + + #forums.Search_colon#  + + +
+
+ + + + + +

@notification_chunk;noquote@

+ + + + + + #forums.Post_a_Reply# + + + #forums.Reply_to_first_post_on_page_label# + + + + Index: openacs-4/contrib/packages/forums/www/message-view.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/message-view.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/message-view.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,113 @@ +ad_page_contract { + + view a message (and its children) + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-25 + @cvs-id $Id: message-view.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} { + message_id:integer,notnull + {display_mode ""} +} + +####################### +# +# First check all reasons why we might abort +# +####################### + +# Load up the message information +forum::message::get -message_id $message_id -array message +if {![array exists message]} { + ns_returnnotfound + ad_script_abort +} + +# Load up the forum information +forum::get -forum_id $message(forum_id) -array forum + +# If disabled! +if {$forum(enabled_p) != "t"} { + ad_returnredirect "./" + ad_script_abort +} + +forum::security::require_read_message -message_id $message_id +forum::security::permissions -forum_id $message(forum_id) permissions + +# Check if the user has admin on the message +set permissions(moderate_p) [forum::security::can_moderate_message_p -message_id $message_id] +if {!${permissions(moderate_p)}} { + set permissions(post_p) [forum::security::can_post_forum_p -forum_id $message(forum_id)] +} else { + set permissions(post_p) 1 +} + +# Check if the message is approved +if {!${permissions(moderate_p)} && ![string equal $message(state) approved]} { + ad_returnredirect "forum-view?forum_id=$message(forum_id)" + ad_script_abort +} + +############################################ +# +# Ok we're not aborting so lets do some work +# +############################################ + +# Create a search form and action when used +set searchbox_p [parameter::get -parameter ForumsSearchBoxP -default 1] +if {$searchbox_p} { + form create search -action search + forums::form::search search + + if {[form is_request search]} { + element set_properties search forum_id -value $message(forum_id) + } +} + + +# If this is a top-level thread, we allow subscriptions here +if { [empty_string_p $message(parent_id)] } { + set notification_chunk [notification::display::request_widget \ + -type forums_message_notif \ + -object_id $message(message_id) \ + -pretty_name $message(subject) \ + -url [ad_conn url]?message_id=$message(message_id) \ + ] +} else { + set notification_chunk "" +} + +set context [list [list "./forum-view?forum_id=$message(forum_id)" "$message(forum_name)"]] +if {![empty_string_p $message(parent_id)]} { + lappend context [list "./message-view?message_id=$message(root_message_id)" "$message(root_subject)"] + lappend context [_ forums.One_Message] +} else { + lappend context "$message(subject)" +} + +if { $permissions(post_p) || [ad_conn user_id] == 0 } { + set reply_url [export_vars -base message-post { { parent_id $message(message_id) } }] +} + +set thread_url [export_vars -base forum-view { { forum_id $message(forum_id) } }] + +set dynamic_script " + + +" + +if {$forum(presentation_type) eq "flat"} { + set display_mode flat +} Index: openacs-4/contrib/packages/forums/www/not-allowed.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/not-allowed.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/not-allowed.adp 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,5 @@ + +Action Not Allowed +@context;noquote@ + +We're sorry, but it appears that you do not have the permission to perform this operation. \ No newline at end of file Index: openacs-4/contrib/packages/forums/www/not-allowed.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/not-allowed.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/not-allowed.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,10 @@ +ad_page_contract { + + Action not allowed. + + @author Lars Pind (lars@pinds.com) + @creation-date 2002-10-14 + @cvs-id $Id: not-allowed.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ +} + +set context [list "Not Allowed"] Index: openacs-4/contrib/packages/forums/www/search.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/search.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/search.adp 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,9 @@ + + @page_title;noquote@ + @context;noquote@ + +
+ + + +
Index: openacs-4/contrib/packages/forums/www/search.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/search.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/search.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,13 @@ +ad_page_contract { + + @author yon@openforce.net + @author rob@thaum.net + @creation-date 2002-07-01 + @cvs-id $Id: search.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} -query { + {forum_id ""} +} + +set page_title [_ forums.Search_Forums] +set context [list $page_title] Index: openacs-4/contrib/packages/forums/www/user-history.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/user-history.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/user-history.adp 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,9 @@ + +#forums.Forums_Posting_hist_lt# @user.full_name;noquote@ +@context;noquote@ + +
+ + + +
Index: openacs-4/contrib/packages/forums/www/user-history.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/forums/www/Attic/user-history.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/forums/www/user-history.tcl 23 Jan 2007 13:24:06 -0000 1.1 @@ -0,0 +1,22 @@ +ad_page_contract { + + Posting History for a User + + @author Ben Adida (ben@openforce.net) + @creation-date 2002-05-29 + @cvs-id $Id: user-history.tcl,v 1.1 2007/01/23 13:24:06 hamiltonc Exp $ + +} { + user_id:integer,notnull + {view "date"} +} + +ad_returnredirect [dotfolio::user::dotfolio_url -user_id $user_id] +ad_script_abort + +# Get user information +oacs::user::get -user_id $user_id -array user + +set context [list [_ forums.Posting_History]] + +ad_return_template