Index: openacs-4/contrib/packages/survey/www/process-response.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/process-response.tcl,v diff -u -r1.10 -r1.11 --- openacs-4/contrib/packages/survey/www/process-response.tcl 16 Mar 2005 12:26:31 -0000 1.10 +++ openacs-4/contrib/packages/survey/www/process-response.tcl 18 Mar 2005 02:28:02 -0000 1.11 @@ -174,10 +174,10 @@ if {[db_string get_response_count {}] == 0} { db_exec_plsql create_response {} - } + } set question_info_list [db_list_of_lists survey_question_info_list {}] - + # in case of editing a response, clear old responses db_dml clear_section_response "" @@ -188,11 +188,11 @@ set presentation_type [lindex $question 3] set required_p [lindex $question 4] set predefined_question_id [lindex $question 5] - + if {[info exists response_to_question($question_id)]} { if {$abstract_data_type=="date" && \ - [exists_and_not_null invalid_date_p($question_id)]} { - set response_value [db_null] + [exists_and_not_null invalid_date_p($question_id)]} { + set response_value [db_null] } else { set response_value [string trim $response_to_question($question_id)] } @@ -203,26 +203,26 @@ # If this is a predefined question, handle it accordingly if {$predefined_question_id != [db_null]} { db_1row predefined "" - + # Predefined DB questions are inserted both in the DB and in the response. if {$action_type=="db"} { # Make sure we deal with dates correctly # If we have an invalid date, insert a NULL value if {[exists_and_not_null invalid_date_p($question_id)]} { set response_value [db_null] } - + # insert value into db db_dml ignore "update $table_name set $column_name=:response_value where $key_name=:user_id" if {![db_resultrows]} { db_dml insert "insert into $table_name ($key_name,$column_name) values (:user_id,_response_value)" } } } - + switch -- $abstract_data_type { "choice" { - if { $presentation_type == "checkbox" } { + if { $presentation_type == "checkbox" || $presentation_type == "checkbox_text" } { # Deal with multiple responses. set checked_responses $response_to_question($question_id) foreach response_value $checked_responses { @@ -237,7 +237,7 @@ if { [empty_string_p $response_value] || [empty_string_p [lindex $response_value 0]] } { set response_value [db_null] } - + db_dml survey_question_response_choice_insert "insert into survey_question_responses (response_id, question_id, choice_id) values (:response_id, :question_id, :response_value)" } @@ -267,63 +267,69 @@ } db_dml survey_question_response_text_insert {} -clobs [list $response_value] - } - "date" { - if { [empty_string_p $response_value] } { - set response_value [db_null] - } - # Make sure we deal with dates correctly - # If we have an invalid date, insert a NULL value - if {[exists_and_not_null invalid_date_p($question_id)]} { - set response_value [db_null] } - db_dml survey_question_response_date_insert {} - } - "blob" { - - if { ![empty_string_p $response_value] } { - # this stuff only makes sense to do if we know the file exists - # cannot use [template::data::transform::file because of the . in the var name - set filename [ns_queryget response_to_question.$question_id] - set tmp_filename [ns_queryget response_to_question.$question_id.tmpfile] - set mime_type [ns_queryget response_to_question.$question_id.content-type] - set file_extension [string tolower [file extension $response_value]] - # remove the first . from the file extension - regsub {\.} $file_extension "" file_extension - - set n_bytes [file size $tmp_filename] - - if { $n_bytes == 0 } { - error "[_ survey.lt_This_should_have_been]" - } else { - set unique_name "${filename}_${response_id}" - if {[ad_conn user_id]=="0"} { - # anonymous answer - set creation_user [db_null] + "date" { + if { [empty_string_p $response_value] } { + set response_value [db_null] + } + # Make sure we deal with dates correctly + # If we have an invalid date, insert a NULL value + if {[exists_and_not_null invalid_date_p($question_id)]} { + set response_value [db_null] + } + db_dml survey_question_response_date_insert {} + } + "blob" { + + if { ![empty_string_p $response_value] } { + # this stuff only makes sense to do if we know the file exists + # cannot use [template::data::transform::file because of the . in the var name + set filename [ns_queryget response_to_question.$question_id] + set tmp_filename [ns_queryget response_to_question.$question_id.tmpfile] + set mime_type [ns_queryget response_to_question.$question_id.content-type] + set file_extension [string tolower [file extension $response_value]] + # remove the first . from the file extension + regsub {\.} $file_extension "" file_extension + + set n_bytes [file size $tmp_filename] + + if { $n_bytes == 0 } { + error "[_ survey.lt_This_should_have_been]" } else { - set creation_user [ad_conn user_id] + set unique_name "${filename}_${response_id}" + if {[ad_conn user_id]=="0"} { + # anonymous answer + set creation_user [db_null] + } else { + set creation_user [ad_conn user_id] + } + if {[info exist upload_file_exist($question_id)]} { + set old_revision_id $upload_file_exist($question_id) + set old_item [db_string get_item_id ""] + set revision_id [cr_import_content -item_id $old_item -creation_user $creation_user -title $filename "" $tmp_filename $n_bytes $mime_type $unique_name ] + db_dml survey_question_response_file_attachment_update "" + db_dml update_item_description "" + } else { + set revision_id [cr_import_content -creation_user $creation_user -title $filename "" $tmp_filename $n_bytes $mime_type $unique_name ] + db_dml survey_question_response_file_attachment_insert "" + } + # we use cr_import_content now --DaveB + # this abstracts out for use the blob handling for oracle or postgresql + # we are linking the file item_id to the survey_question_response attachment_answer field now + } - if {[info exist upload_file_exist($question_id)]} { - set old_revision_id $upload_file_exist($question_id) - set old_item [db_string get_item_id ""] - set revision_id [cr_import_content -item_id $old_item -creation_user $creation_user -title $filename "" $tmp_filename $n_bytes $mime_type $unique_name ] - db_dml survey_question_response_file_attachment_update "" - db_dml update_item_description "" - } else { - set revision_id [cr_import_content -creation_user $creation_user -title $filename "" $tmp_filename $n_bytes $mime_type $unique_name ] - db_dml survey_question_response_file_attachment_insert "" - } - # we use cr_import_content now --DaveB - # this abstracts out for use the blob handling for oracle or postgresql - # we are linking the file item_id to the survey_question_response attachment_answer field now + } + } + } - } - } - } + # SB: each of these widgets has an additional element, the text field, that has to be dealt with + if { $presentation_type == "checkbox_text" || $presentation_type == "radio_text" || $presentation_type == "select_text" } { + set response_value [ns_set get [ns_getform] "response_to_question.${question_id}.text"] + db_dml survey_question_choice_shorttext_insert {} + } } } } -} # Look for next section set section_ids [survey_next_sections -edit_p $edit_p $survey_id $section_id $response_id]