Index: openacs-4/contrib/packages/survey/tcl/survey-form-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/tcl/Attic/survey-form-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/survey/tcl/survey-form-procs.tcl 13 Jan 2005 13:54:39 -0000 1.2 +++ openacs-4/contrib/packages/survey/tcl/survey-form-procs.tcl 18 Mar 2005 02:28:02 -0000 1.3 @@ -45,19 +45,14 @@ [list "section_info$section_id:text(inform)" {label ""} {value $section_info(description)} {section $section_info(name)}] ] - db_foreach get_questions { - select question_id - from survey_questions - where section_id=:section_id - order by sort_order - } { + db_foreach get_questions {} { survey::form::create_ad_form_element \ -form $form \ -question_id $question_id \ -response_id $response_id \ -mode $mode \ -edit_p $edit_p - } + } } @@ -92,40 +87,16 @@ set element_name "response_to_question.$question_id" - db_1row get_question_properties { - select section_id, - sort_order, - question_text, - abstract_data_type, - required_p, - active_p, - presentation_type, - presentation_options, - presentation_alignment, - creation_user, - creation_date, - predefined_question_id - from survey_questions, - acs_objects - where object_id = question_id - and question_id = :question_id - } + db_1row get_question_properties {} set user_value "" + set selected_choices [list] if { $predefined_question_id != [db_null] } { # question is a predefined question. If it has already been answered, get the last response value from the db # if it is a predefined question with action_type="db" get the value from the db instead. - db_1row predefined_question_data { - select action_type, - abstract_data_type, - table_name, - column_name, - key_name - from survey_predefined_questions - where predefined_question_id = :predefined_question_id - } + db_1row predefined_question_data {} if {[string equal $action_type "db"]} { # select preselected value from the db @@ -154,48 +125,13 @@ } else { # select preselected value from latest response set user_id [ad_conn user_id] - if {[db_0or1row locate_predef_preselect { - select question_id as preselect_question_id, - object_id as response_id - from survey_question_responses, - acs_objects - where question_id in ( - select question_id - from survey_questions - where predefined_question_id = :predefined_question_id - ) - and object_type = 'survey_response' - and response_id = object_id - and creation_date = (select min(creation_date) - from survey_question_responses, - acs_objects - where question_id in ( - select question_id - from survey_questions - where predefined_question_id = :predefined_question_id - ) - and object_type = 'survey_response' - and response_id=object_id - ) - }]} { + if {[db_0or1row locate_predef_preselect {}]} { set count 0 - db_foreach prev_response_query_predef { - select choice_id, - boolean_answer, - clob_answer, - number_answer, - varchar_answer, - to_char(date_answer,'YYYY MM DD HH24 MI SS') as date_answer, - attachment_answer - from survey_question_responses - where question_id = :preselect_question_id - and response_id = :response_id - } { + db_foreach prev_response_query_predef {} { incr count - - if {[string equal $presentation_type "checkbox"]} { - set selected_choices($choice_id) "t" - } + if {![empty_string_p $choice_id]} { + lappend selected_choices $choice_id + } } if_no_rows { set choice_id 0 set boolean_answer "" @@ -221,22 +157,10 @@ set user_id [ad_conn user_id] set count 0 - db_foreach prev_response_query { - select choice_id, - boolean_answer, - clob_answer, - number_answer, - varchar_answer, - to_char(date_answer,'YYYY MM DD HH24 MI SS') as date_answer, - attachment_answer - from survey_question_responses - where question_id = :question_id - and response_id = :response_id - } { + db_foreach prev_response_query {} { incr count - - if {[string equal $presentation_type "checkbox"]} { - set selected_choices($choice_id) "t" + if {![empty_string_p $choice_id]} { + lappend selected_choices $choice_id } } if_no_rows { set choice_id 0 @@ -253,7 +177,7 @@ if {$edit_previous_response_p} { switch -- $abstract_data_type { "choice" { - set user_value $choice_id + set user_value [join $selected_choices " "] } "shorttext" { set user_value $varchar_answer @@ -308,6 +232,7 @@ "date" { set element_type "date(date)" } + "select_text" - "select" { if { [string equal $abstract_data_type "boolean"] } { if {![empty_string_p $presentation_options]} { @@ -324,25 +249,20 @@ # at some point, we may want to add a UI option for the admin # to sepcify multiple or not for select set optionlist [list] - db_foreach question_choices { - select choice_id, - label - from survey_question_choices - where question_id = :question_id - order by sort_order - } { + db_foreach question_choices {} { lappend optionlist [list $label $choice_id] } set options $optionlist - set pretty_user_value [db_string get_pretty_value { - select label - from survey_question_choices - where choice_id = :user_value - } -default ""] + set pretty_user_value [db_string get_pretty_value {} -default ""] } - set element_type "text(select)" + if { $presentation_type == "select_text" } { + set element_type "text(select_text)" + } else { + set element_type "text(select)" + } set element_param_list {{options $options}} } + "radio_text" - "radio" { if { [string equal $abstract_data_type "boolean"] } { if {![empty_string_p $presentation_options]} { @@ -358,40 +278,34 @@ set pretty_user_value [string map {t $choice_t f $choice_f} $user_value] } else { set optionlist [list] - db_foreach question_choices_2 { - select choice_id, - label - from survey_question_choices - where question_id = :question_id - order by sort_order - } { + db_foreach question_choices {} { # replace {xxx.gif} by image inclusion regsub -all "\{(\[^\{\}\]*)\}" $label {} label lappend optionlist [list $label $choice_id] } set options $optionlist - set pretty_user_value [db_string get_pretty_value { - select label - from survey_question_choices - where choice_id = :user_value - } -default ""] + set pretty_user_value [db_string get_pretty_value {} -default ""] } - set element_type "text(radio)" + if {$presentation_type == "radio_text"} { + set element_type "text(radio_text)" + } else { + set element_type "text(radio)" + } set element_param_list {{options $options}} } + "checkbox_text" - "checkbox" { set choices [list] set optionlist [list] - db_foreach question_choices_3 { - select * - from survey_question_choices - where question_id = :question_id - order by sort_order - } { + db_foreach question_choices_all {} { lappend optionlist [list $label $choice_id] } set options $optionlist - set element_type "text(checkbox)" + if { $presentation_type == "checkbox_text" } { + set element_type "text(checkbox_text)" + } else { + set element_type "text(checkbox)" + } set element_param_list {{options $options}} } } @@ -402,19 +316,29 @@ # we allow multiple values here only if not on display # mode if {[string equal $mode display]} { - set pretty_user_value_list [db_list get_choice_label " - select label - from survey_question_choices - where choice_id in ($user_value) - "] + set pretty_user_value_list [db_list get_choice_label {}] set pretty_user_value [join $pretty_user_value_list ", "] regsub -all -- {\$} $pretty_user_value {\\$} pretty_user_value lappend element_param_list [list value $pretty_user_value] } else { lappend element_param_list [list values $user_value] } - } else { + } elseif { $presentation_type == "checkbox_text" } { + # SB: checkbox_text widget expects "value" to be in the format {{choice ids} text} + set text_value [survey::form::get_response_text -response_id $response_id -question_id $question_id \ + -abstract_data_type "choice"] if {[string equal $mode display]} { + set pretty_user_value_list [db_list get_choice_label {}] + set pretty_user_value [join $pretty_user_value_list ", "] + regsub -all -- {\$} $pretty_user_value {\\$} pretty_user_value + lappend element_param_list [list value $pretty_user_value] + } else { + lappend element_param_list [list value "\{$user_value\} \"$text_value\""] + } + } elseif { $presentation_type == "select_text" || $presentation_type == "radio_text" } { + set text_value [survey::form::get_response_text -response_id $response_id -question_id $question_id \ + -abstract_data_type $abstract_data_type] + if {[string equal $mode display]} { if { ![string equal $abstract_data_type "boolean"] } { # boolean is a special case so we do not replace # their dollar signs @@ -424,6 +348,19 @@ regsub -all -- {\n} $pretty_user_value {
} pretty_user_value lappend element_param_list [list value $pretty_user_value] } else { + lappend element_param_list [list value "$user_value \"$text_value\""] + } + } else { + if {[string equal $mode display]} { + if { ![string equal $abstract_data_type "boolean"] } { + # boolean is a special case so we do not replace + # their dollar signs + regsub -all -- {\$} $pretty_user_value {\\$} pretty_user_value + } + # this takes care of textareas + regsub -all -- {\n} $pretty_user_value {
} pretty_user_value + lappend element_param_list [list value $pretty_user_value] + } else { lappend element_param_list [list value $user_value] } } @@ -454,3 +391,28 @@ } +ad_proc -public survey::form::get_response_text { + {-response_id:required} + {-question_id:required} + {-abstract_data_type:required} +} { + Utility procedure for checkbox_text, radio_text and select_text widgets. + Returns the value of the text part of the widget. + Used for retrieving the response for editing purposes. + + @author simon@simonbuckle.com +} { + set txt "" + + # only return the text if the widget is one of the allowed types + switch -- $abstract_data_type { + "choice" { + set txt [db_string choice_text_value {} -default ""] + } + "boolean" { + set txt [db_string boolean_text_value {} -default ""] + } + } + + return $txt +} \ No newline at end of file