ad_page_contract {

    @author yon@openforce.net
    @creation-date 2002-07-01
    @cvs-id $Id: search-chunk.tcl,v 1.3.2.1 2007/03/04 21:21:26 donb Exp $

}
set package_id [ad_conn package_id]
set useScreenNameP [parameter::get -parameter "UseScreenNameP" -default 0]

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"
        }
	
	if { $useScreenNameP == 1 } {
	    db_multirow -extend { screen_name } messages $query {} {
		set posting_date_pretty [lc_time_fmt $posting_date_ansi "%x %X"]
		set screen_name [db_string select_screen_name {select screen_name from users where user_id = :user_id}]
	    }
	} else {
	    db_multirow messages $query {} {
		set posting_date_pretty [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
    }
}
