Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-ae-2.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2.tcl 19 Sep 2003 16:48:04 -0000 1.1 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2.tcl 23 Oct 2003 06:22:26 -0000 1.2 @@ -6,7 +6,7 @@ @cvs-id $Id$ } { predefined_question_id:optional - question_text + question_text:html question_html_p:boolean presentation_type } @@ -19,21 +19,23 @@ ad_form -name predef -form { predefined_question_id:key + {question_text_new:text(hidden) {value $question_text}} {question_text:text(hidden) {value $question_text}} + {question_html_p_new:text(hidden) {value $question_html_p}} {question_html_p:text(hidden) {value $question_html_p}} + {presentation_type_new:text(hidden) {value $presentation_type}} {presentation_type:text(hidden) {value $presentation_type}} {question_text_inform:text(inform) {label "Question"} {html {rows 5 cols 70}} {value $question_text}} } -select_query { - select * from survey_predefined_questions where predefined_question_id=:predefined_question_id + select abstract_data_type,presentation_options,presentation_alignment,summary_type,action_type,tcl,table_name,column_name,key_name from survey_predefined_questions where predefined_question_id=:predefined_question_id } if {[info exist predefined_question_id]} { # get choices set valid_responses "" - set valid_responses_list [db_list survey_question_valid_responses {}] - set response_list "" - foreach response $valid_responses_list { - append valid_responses "$response\n" + db_foreach survey_question_valid_responses "" { + lappend choice_id_to_update_list $choice_id + append valid_responses "$label\n" } } else { set valid_responses "" @@ -155,22 +157,59 @@ if { $presentation_type == "checkbox" || $presentation_type == "radio" || $presentation_type == "select" } { if { $abstract_data_type == "choice" } { set responses [split $valid_responses "\n"] - set count 0 + set sort_order 0 foreach response $responses { - set trimmed_response [string trim $response] - if { [empty_string_p $trimmed_response] } { + set choice_label [string trim $response] + if { [empty_string_p $choice_label] } { # skip empty lines continue - } + } else { ### added this next line to - set choice_id [db_nextval survey_choice_id_sequence] db_dml insert_survey_question_choice "" - incr count + set new_choice_id [db_nextval survey_choice_id_sequence] + db_dml insert_new_choice "" + incr sort_order + } } } - } + } } } -edit_data { db_dml edit_predefined_question "" + + set responses [split $valid_responses "\n"] + set count 0 + set response_list "" + foreach response $responses { + set trimmed_response [string trim $response] + if { [empty_string_p $trimmed_response] } { + # skip empty lines + continue + } + + lappend response_list [list "$trimmed_response" "$count"] + incr count + } + + set sort_order 0 + foreach one_response $response_list { + set choice_label [lindex $one_response 0] + set sort_order [lindex $one_response 1] + set choice_id_to_update [lindex $choice_id_to_update_list $sort_order] + if {[empty_string_p $choice_id_to_update]} { + set new_choice_id [db_nextval survey_choice_id_sequence] + db_dml insert_new_choice {} + } else { + + db_dml update_new_choice {} + } + incr sort_order + } + while {[llength $choice_id_to_update_list] >= $sort_order} { + set choice_id_to_delete [lindex $choice_id_to_update_list $sort_order] + db_dml delete_old_choice {} + incr sort_order + } + } -after_submit { ad_returnredirect predefined-question-admin ad_script_abort