Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-2-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-2-oracle.xql,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/survey/www/admin/predefined-question-2-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-2-oracle.xql 23 Oct 2003 06:22:26 -0000 1.2 @@ -45,5 +45,16 @@ + + + insert into + survey_question_choices(choice_id,predef_choice_id,question_id,label,numeric_value,sort_order,presentation_alignment,more_info_type) + (select + survey_choice_id_sequence.nextval,choice_id,:question_id,label,numeric_value,sort_order,presentation_alignment,more_info_type + from survey_predef_question_choices where question_id=:predefined_question_id) + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-2-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-2-postgresql.xql,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/survey/www/admin/predefined-question-2-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-2-postgresql.xql 23 Oct 2003 06:22:26 -0000 1.2 @@ -45,4 +45,14 @@ + + + insert into + survey_question_choices(choice_id,predef_choice_id,question_id,label,numeric_value,sort_order,presentation_alignment,more_info_type) + (select + nextval('survey_choice_id_sequence'),choice_id,:question_id,label,numeric_value,sort_order,presentation_alignment,more_info_type + from survey_predef_question_choices where question_id=:predefined_question_id) + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-2.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/survey/www/admin/predefined-question-2.tcl 19 Sep 2003 16:48:04 -0000 1.1 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-2.tcl 23 Oct 2003 06:22:26 -0000 1.2 @@ -82,7 +82,6 @@ if { $presentation_type == "checkbox" || $presentation_type == "radio" || $presentation_type == "select" } { if { $abstract_data_type == "choice" } { - set new_choice [db_nextval survey_choice_id_sequence] db_dml add_new_choices "" } } Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-2.xql,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/survey/www/admin/predefined-question-2.xql 19 Sep 2003 16:48:04 -0000 1.1 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-2.xql 23 Oct 2003 06:22:26 -0000 1.2 @@ -34,21 +34,6 @@ - - - insert into - survey_question_choices(choice_id,predef_choice_id,question_id,label,numeric_value,sort_order,presentation_alignment,more_info_type) - (select - :new_choice,choice_id,:question_id,label,numeric_value,sort_order,presentation_alignment,more_info_type - from survey_predef_question_choices where question_id=:predefined_question_id) - - - - - - - - select distinct survey_question_all_choices(question_id) as 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 Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-ae-2.xql,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2.xql 19 Sep 2003 16:48:04 -0000 1.1 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2.xql 23 Oct 2003 06:22:26 -0000 1.2 @@ -3,29 +3,45 @@ - select label from survey_predef_question_choices where question_id=:predefined_question_id + select label,choice_id from survey_predef_question_choices where question_id=:predefined_question_id update survey_predefined_questions set - question_text=:question_text where predefined_question_id=:predefined_question_id + question_text=:question_text_new where predefined_question_id=:predefined_question_id + - - - insert into survey_predef_question_choices (choice_id, question_id, label, sort_order) - values (:choice_id, :predefined_question_id, :trimmed_response, :count) - + + +insert into survey_predef_question_choices +(choice_id, question_id, label, sort_order) +values (:new_choice_id, :predefined_question_id, :choice_label, :sort_order) + + + +update survey_predef_question_choices + set label=:choice_label where choice_id=:choice_id_to_update + + + + + +delete from survey_predef_question_choices where choice_id = :choice_id_to_delete + + + update survey_predefined_questions set - question_text=:question_text,question_html_p=:question_html_p,abstract_data_type=:abstract_data_type,presentation_type=:presentation_type,presentation_options=:presentation_options,presentation_alignment=:presentation_alignment,action_type=:action_type,table_name=:table_name,column_name=:column_name,key_name=:key_name + question_text=:question_text_new,question_html_p=:question_html_p_new,abstract_data_type=:abstract_data_type,presentation_type=:presentation_type_new,presentation_options=:presentation_options,presentation_alignment=:presentation_alignment,action_type=:action_type,table_name=:table_name,column_name=:column_name,key_name=:key_name where predefined_question_id=:predefined_question_id Index: openacs-4/contrib/packages/survey/www/admin/question-modify.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-modify.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/survey/www/admin/question-modify.tcl 19 Sep 2003 16:48:04 -0000 1.1 +++ openacs-4/contrib/packages/survey/www/admin/question-modify.tcl 23 Oct 2003 06:22:26 -0000 1.2 @@ -129,24 +129,24 @@ } set choice_id_to_update_list [db_list get_choice_id {}] - set choice_count 0 + set sort_order 0 foreach one_response $response_list { - set choice_name [lindex $one_response 0] - set choice_value [lindex $one_response 1] - set choice_id_to_update [lindex $choice_id_to_update_list $choice_count] + 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 choice_count + incr sort_order } - while {[llength $choice_id_to_update_list] >= $choice_count} { - set choice_id_to_delete [lindex $choice_id_to_update_list $choice_count] + + 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 choice_count + incr sort_order } } Index: openacs-4/contrib/packages/survey/www/admin/question-modify.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-modify.xql,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/survey/www/admin/question-modify.xql 19 Sep 2003 16:48:04 -0000 1.1 +++ openacs-4/contrib/packages/survey/www/admin/question-modify.xql 23 Oct 2003 06:22:26 -0000 1.2 @@ -83,14 +83,14 @@ insert into survey_question_choices (choice_id, question_id, label, sort_order) -values (:new_choice_id, :question_id, :choice_name, :choice_value) +values (:new_choice_id, :question_id, :choice_label, :sort_order) update survey_question_choices - set label=:choice_name where choice_id=:choice_id_to_update + set label=:choice_label where choice_id=:choice_id_to_update