Index: openacs-4/packages/survey/www/admin/process-response.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/process-response.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/survey/www/admin/process-response.tcl 12 Feb 2019 18:45:14 -0000 1.9 +++ openacs-4/packages/survey/www/admin/process-response.tcl 3 Sep 2024 15:37:54 -0000 1.10 @@ -54,7 +54,7 @@ # in ad_page_contract. Because :multiple flag will sorround empty # strings and all multiword values with one level of curly braces {} # we need to get rid of them for almost any abstract_data_type - # except 'choice', where this is intended behaviour. Why bother + # except 'choice', where this is intended behavior. Why bother # with :multiple flag at all? Because otherwise we would lost all # but first value for 'choice' abstract_data_type - see ad_page_contract # doc and code for more info. @@ -78,8 +78,8 @@ set ok [ad_page_contract_filter_proc_date "date" date_value] if {$ok} { set response_to_question($question_id) [ns_buildsqldate $date_value(month) \ - $date_value(day) \ - $date_value(year)] + $date_value(day) \ + $date_value(year)] } else { ad_complain "Please make sure your dates are valid." } @@ -89,11 +89,11 @@ set response_value [string trim $response_to_question($question_id)] } elseif {$required_p == "t"} { - # When the administrator edits a survey, the file is not - # prefilled into the form like the rest of the fields. - # If the question is a file_upload and we are editing, - # it is not required to enter a file. Instead, the - # file from the prior response will be used. + # When the administrator edits a survey, the file is not + # prefilled into the form like the rest of the fields. + # If the question is a file_upload and we are editing, + # it is not required to enter a file. Instead, the + # file from the prior response will be used. if { $abstract_data_type ne "blob" || $initial_response_id eq ""} { lappend questions_with_missing_responses $question_text @@ -117,15 +117,15 @@ ad_complain "The response to \"$question_text\" must be an integer. Your answer was \"$response_value\"." continue - } } + } } if { $abstract_data_type eq "blob" } { set tmp_filename $response_to_question($question_id.tmpfile) set n_bytes [file size $tmp_filename] if { $n_bytes == 0 && $required_p == "t" && - $initial_response_id eq ""} { + $initial_response_id eq ""} { ad_complain "Your file is zero-length. Either you attempted to upload a zero length file, a file which does not exist, or something went wrong during the transfer." } @@ -153,7 +153,7 @@ set user_id [ad_conn user_id] -get_survey_info -survey_id $survey_id +survey::get_info -survey_id $survey_id set type $survey_info(type) set survey_id $survey_info(survey_id) set survey_name $survey_info(name) @@ -216,92 +216,94 @@ # Deal with multiple responses. set checked_responses $response_to_question($question_id) foreach response_value $checked_responses { - db_dml survey_question_response_checkbox_insert "insert into survey_question_responses (response_id, question_id, choice_id) - values (:response_id, :question_id, :response_value)" + values (:response_id, :question_id, :response_value)" } } else { + if { [lindex $response_value 0] eq "" } { + set response_value "" + } 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)" + values (:response_id, :question_id, :response_value)" } } "shorttext" { db_dml survey_question_choice_shorttext_insert "insert into survey_question_responses (response_id, question_id, varchar_answer) - values (:response_id, :question_id, :response_value)" + values (:response_id, :question_id, :response_value)" } "boolean" { - db_dml survey_question_response_boolean_insert "insert into survey_question_responses (response_id, question_id, boolean_answer) - values (:response_id, :question_id, :response_value)" + values (:response_id, :question_id, :response_value)" } "integer" - "number" { db_dml survey_question_response_integer_insert "insert into survey_question_responses (response_id, question_id, number_answer) - values (:response_id, :question_id, :response_value)" + values (:response_id, :question_id, :response_value)" } "text" { - db_dml survey_question_response_text_insert " - insert into survey_question_responses - (response_id, question_id, clob_answer) - values (:response_id, :question_id, empty_clob()) - returning clob_answer into :1" -clobs [list $response_value] - } - "date" { +insert into survey_question_responses +(response_id, question_id, clob_answer) +values (:response_id, :question_id, empty_clob()) +returning clob_answer into :1" -clobs [list $response_value] + } + "date" { + db_dml survey_question_response_date_insert "insert into survey_question_responses (response_id, question_id, date_answer) +values (:response_id, :question_id, :response_value)" + } + "blob" { - db_dml survey_question_response_date_insert "insert into survey_question_responses (response_id, question_id, date_answer) - values (:response_id, :question_id, :response_value)" - } - "blob" { + if { $response_value ne "" } { + # this stuff only makes sense to do if we know the file exists + set tmp_filename $response_to_question($question_id.tmpfile) - if { $response_value ne "" } { - # this stuff only makes sense to do if we know the file exists - set tmp_filename $response_to_question($question_id.tmpfile) + set file_extension [string tolower [file extension $response_value]] + # remove the first . from the file extension + regsub {\.} $file_extension "" file_extension + set guessed_file_type [ns_guesstype $response_value] - set file_extension [string tolower [file extension $response_value]] - # remove the first . from the file extension - regsub {\.} $file_extension "" file_extension - set guessed_file_type [ns_guesstype $response_value] - - set n_bytes [file size $tmp_filename] - # strip off the C:\directories... crud and just get the file name - if {![regexp {([^/\\]+)$} $response_value match client_filename]} { + set n_bytes [file size $tmp_filename] + # strip off the C:\directories... crud and just get the filename + if {![regexp {([^/\\]+)$} $response_value match client_filename]} { # couldn't find a match - set client_filename $response_value - } - if { $n_bytes == 0 } { - error "This should have been checked earlier." - } else { - set unique_name "${response_value}_${response_id}" - set mime_type [cr_filename_to_mime_type -create $client_filename] + set client_filename $response_value + } + if { $n_bytes == 0 } { + error "This should have been checked earlier." + } else { + set unique_name "${response_value}_${response_id}" + set mime_type [cr_filename_to_mime_type -create $client_filename] - set revision_id [cr_import_content -title $client_filename "" $tmp_filename $n_bytes $mime_type $unique_name ] - # 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 + set revision_id [cr_import_content -title $client_filename "" $tmp_filename $n_bytes $mime_type $unique_name ] +# 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 db_dml survey_question_response_file_attachment_insert "" - } - } else { - # There was no response. + } + } else { + # There was no response. - if {$initial_response_id ne ""} { - # There was a prior response - # Get the revision_id for this question from the - # prior question. + if {$initial_response_id ne ""} { + # There was a prior response + # Get the revision_id for this question from the + # prior question. - if {[db_0or1row survey_prior_attachment_response {}]} { - set revision_id $attachment_answer - db_dml survey_question_response_file_attachment_insert "" - } - } - } - } - } - } - } + if {[db_0or1row survey_prior_attachment_response {}]} { + set revision_id $attachment_answer + db_dml survey_question_response_file_attachment_insert "" + } + + } + + } + } + } + } } +} + if {[info exists return_url] && $return_url ne ""} { ad_returnredirect "$return_url" ad_script_abort @@ -310,6 +312,7 @@ ad_return_template } + # Local variables: # mode: tcl # tcl-indent-level: 4