Index: openacs-4/packages/survey/www/admin/responses-export.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/responses-export.tcl,v diff -u -r1.13 -r1.14 --- openacs-4/packages/survey/www/admin/responses-export.tcl 27 Jun 2015 20:46:16 -0000 1.13 +++ openacs-4/packages/survey/www/admin/responses-export.tcl 3 Sep 2024 15:37:54 -0000 1.14 @@ -10,10 +10,10 @@ } { survey_id:naturalnum,notnull - {unique_users_p:boolean f} + {unique_users_p:boolean,notnull f} on_what_id:naturalnum,optional - {start:naturalnum 1} - {end:naturalnum 10000} + {start:naturalnum,notnull 1} + {end:naturalnum,notnull 10000} } set csv_export "" set package_id [ad_conn package_id] @@ -22,7 +22,7 @@ set n_responses [db_string get_n_responses {}] ns_log notice "DAVEB: n_responses=$n_responses" if {$n_responses==0} { - get_survey_info -survey_id $survey_id + survey::get_info -survey_id $survey_id set context [list [list [export_vars -base one {survey_id}] $survey_info(name)] "[_ survey.CSV_Export]"] ad_return_template "no-responses" return @@ -40,31 +40,31 @@ append headline "\"" set question_data_type($question_id) $abstract_data_type switch -- $abstract_data_type { - "date" { - set question_column($question_id) "date_answer" - } - "text" { - set question_column($question_id) "clob_answer" - } - "shorttext" { - set question_column($question_id) "varchar_answer" - } - "boolean" { - set question_column($question_id) "boolean_answer" - } - "integer" - - "number" { - set question_column($question_id) "number_answer" - } - "choice" { - set question_column($question_id) "label" - } - "blob" { - set question_column($question_id) "attachment_answer" - } - default { - set question_column($question_id) "varchar_answer" - } + "date" { + set question_column($question_id) "date_answer" + } + "text" { + set question_column($question_id) "clob_answer" + } + "shorttext" { + set question_column($question_id) "varchar_answer" + } + "boolean" { + set question_column($question_id) "boolean_answer" + } + "integer" - + "number" { + set question_column($question_id) "number_answer" + } + "choice" { + set question_column($question_id) "label" + } + "blob" { + set question_column($question_id) "attachment_answer" + } + default { + set question_column($question_id) "varchar_answer" + } } } @@ -77,61 +77,61 @@ set current_question_list [list] set csv_export "" set r 0 -ReturnHeaders "application/text" +util_return_headers "application/text" ns_write "$headline \r\n" db_foreach get_all_survey_question_responses "" { if { $response_id != $current_response_id } { - if { $current_question_id ne "" } { - append current_response ",\"[join $current_question_list ","]\"" - } + if { $current_question_id ne "" } { + append current_response ",\"[join $current_question_list ","]\"" + } - if { $current_response_id ne "" } { - append csv_export "$current_response \r\n" - } - set current_response_id $response_id + if { $current_response_id ne "" } { + append csv_export "$current_response \r\n" + } + set current_response_id $response_id - set creation_date_ansi [lc_time_system_to_conn $creation_date_ansi] - set creation_date_pretty [lc_time_fmt $creation_date_ansi "%x %X"] - set one_response [list $email $first_names $last_name $user_id $creation_date_pretty $response_id] - regsub -all {"} $one_response {""} one_response - set current_response "\"[join $one_response {","}]\"" + set creation_date_ansi [lc_time_system_to_conn $creation_date_ansi] + set creation_date_pretty [lc_time_fmt $creation_date_ansi "%x %X"] + set one_response [list $email $first_names $last_name $user_id $creation_date_pretty $response_id] + regsub -all {"} $one_response {""} one_response + set current_response "\"[join $one_response {","}]\"" - set current_question_id "" - set current_question_list [list] + set current_question_id "" + set current_question_list [list] } set response_value [set $question_column($question_id)] # Properly escape double quotes to make Excel & co happy regsub -all {"} $response_value {""} response_value - + # Remove any CR or LF characters that may be present in text fields regsub -all {[\r\n]} $response_value {} response_value if { $question_id != $current_question_id } { - if { $current_question_id ne "" } { - append current_response ",\"[join $current_question_list ","]\"" - } - set current_question_id $question_id - set current_question_list [list] + if { $current_question_id ne "" } { + append current_response ",\"[join $current_question_list ","]\"" + } + set current_question_id $question_id + set current_question_list [list] } # decode boolean answers - if {$question_data_type($question_id)=="boolean"} { - set response_value [survey_decode_boolean_answer -response $response_value -question_id $question_id] - } - if {$question_data_type($question_id)=="blob"} { - set response_value [db_string get_filename {} -default ""] - } + if {$question_data_type($question_id)=="boolean"} { + set response_value [survey::decode_boolean_answer -response $response_value -question_id $question_id] + } + if {$question_data_type($question_id)=="blob"} { + set response_value [db_string get_filename {} -default ""] + } lappend current_question_list $response_value - - incr r - if {$r>99} { - ns_write "${csv_export}" - set csv_export "" - set r 0 - } + incr r + if {$r>99} { + ns_write "${csv_export}" + set csv_export "" + set r 0 + } + } if { $current_question_id ne "" } { @@ -141,8 +141,14 @@ append csv_export "$current_response\r\n" } if {$csv_export eq ""} { - set csv_export "\r\n" + set csv_export "\r\n" } ns_write $csv_export ns_conn close + +# Local variables: +# mode: tcl +# tcl-indent-level: 4 +# indent-tabs-mode: nil +# End: