Forum OpenACS Q&A: Response to News items on index page

Collapse
Posted by Alex Sokoloff on
Filching the code from news/index.tcl worked well for me. You'll need to edit a little to give a more compact display of the news. Try something like this (you might have to look at the page source to get some of the html, which the pre tag doesn't seem to be smart enough to interpret as code):

#
# /www/news/index.tcl
#
# news main page
#
# Author: jkoontz@arsdigita.com March 8, 2000
#
# index.tcl,v 3.2 2000/03/10 23:45:33 jkoontz Exp

# Note: if page is accessed through /groups pages then group_id and
# group_vars_set are already set up in the environment by the
# ug_serve_section. group_vars_set contains group related variables
# (group_id, group_name, group_short_name, group_admin_email,
# group_public_url, group_admin_url, group_public_root_url,
# group_admin_root_url, group_type_url_p, group_context_bar_list and
# group_navbar_list)

set_the_usual_form_variables 0
# possibly archive_p
# maybe scope, maybe scope related variables (user_id, group_id, on_which_group, on_what_id)

ad_scope_error_check

set db_conns [ns_db gethandle [philg_server_default_pool] 2]
set db [lindex $db_conns 0]
set db_sub [lindex $db_conns 1]
ad_scope_authorize $db $scope all group_member all


if { ![info exists user_id] } {
    set user_id 0
}
if { ![info exists group_id] } {
    set group_id 0
}

# Create a clause for returning the postings for relavent groups
set newsgroup_clause "(newsgroup_id = [join [news_newsgroup_id_list $db $user_id $group_id] " or newsgroup_id = "])"

if { [info exists archive_p] && $archive_p } {
    set query "
    select news_item_id, title, release_date, body, html_p
    from news_items
    where sysdate() > expiration_date
    and $newsgroup_clause
    and approval_state = 'approved'
    order by release_date desc, creation_date desc"
} else {
    set query "
    select news_item_id, title, release_date, body, html_p
    from news_items
    where sysdate() between release_date and expiration_date
    and $newsgroup_clause
    and approval_state = 'approved'
    order by release_date desc, creation_date desc"
}

set selection [ns_db select $db $query]

set counter 0
while { [ns_db getrow $db $selection] } {
    set_variables_after_query
    incr counter
    append page_content "<li>[util_AnsiDatetoPrettyDate $release_date]: "
    append page_content "<a href="/news/item.tcl?[export_url_scope_vars news_item_id]">$title</a>"
}

if { $counter == 0 } {
    append page_content "None."
}

append page_content "
</ul>
"

ns_db releasehandle $db
ns_db releasehandle $db_sub