Index: openacs-4/packages/assessment/www/asm-admin/item-add-mc.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/asm-admin/item-add-mc.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/assessment/www/asm-admin/item-add-mc.tcl 21 Feb 2005 14:32:56 -0000 1.3 +++ openacs-4/packages/assessment/www/asm-admin/item-add-mc.tcl 11 Mar 2005 18:54:12 -0000 1.4 @@ -30,10 +30,13 @@ set page_title [_ assessment.add_item_type_mc] set context_bar [ad_context_bar [list [export_vars -base one-a {assessment_id}] $assessment_data(title)] $page_title] +set folder_id [as::assessment::folder_id -package_id $package_id] set boolean_options [list [list "[_ assessment.yes]" t] [list "[_ assessment.no]" f]] set correct_options [list [list "[_ assessment.yes]" t]] +set choice_sets [db_list_of_lists existing_choice_sets {}] +set choice_sets [concat [list [list "" ""]] $choice_sets] set display_types [list] foreach display_type [db_list display_types {}] { lappend display_types [list "[_ assessment.item_display_$display_type]" $display_type] @@ -48,6 +51,7 @@ {num_correct_answers:text,optional,nospell {label "[_ assessment.num_Correct_Answer]"} {html {size 5 maxlength 5}} {help_text "[_ assessment.num_Correct_help]"}} {num_answers:text,optional,nospell {label "[_ assessment.num_Answers]"} {html {size 5 maxlength 5}} {help_text "[_ assessment.num_Answers_help]"}} {display_type:text(select) {label "[_ assessment.Display_Type]"} {options $display_types} {help_text "[_ assessment.Display_Type_help]"}} + {mc_id:text(select),optional {label "[_ assessment.Choice_Sets]"} {options $choice_sets} {help_text "[_ assessment.Choice_Sets_help]"}} } # add form entries for each choice @@ -70,6 +74,7 @@ append ad_form_code "\}" eval ad_form -extend -name item_add_mc $ad_form_code + set edit_request "{ set title \"\" set increasing_p f @@ -91,16 +96,20 @@ set edit_data "{ db_transaction { if {!\[db_0or1row item_type {}\] || \$object_type != \"as_item_type_mc\"} { - set mc_id \[as::item_type_mc::new \\ + if {\[empty_string_p \$mc_id\]} { + set new_mc_id \[as::item_type_mc::new \\ -title \$title \\ -increasing_p \$increasing_p \\ -allow_negative_p \$negative_p \\ -num_correct_answers \$num_correct_answers \\ -num_answers \$num_answers\] + } else { + set new_mc_id \$mc_id + } if {!\[info exists object_type\]} { # first item type mapped - as::item_rels::new -item_rev_id \$as_item_id -target_rev_id \$mc_id -type as_item_type_rel + as::item_rels::new -item_rev_id \$as_item_id -target_rev_id \$new_mc_id -type as_item_type_rel } else { # old item type existing set as_item_id \[as::item::new_revision -as_item_id \$as_item_id\] @@ -109,22 +118,27 @@ } else { # old mc item type existing set as_item_id \[as::item::new_revision -as_item_id \$as_item_id\] - set mc_id \[as::item_type_mc::edit \\ + if {\[empty_string_p \$mc_id\]} { + set new_mc_id \[as::item_type_mc::edit \\ -as_item_type_id \$as_item_type_id \\ -title \$title \\ -increasing_p \$increasing_p \\ -allow_negative_p \$negative_p \\ -num_correct_answers \$num_correct_answers \\ -num_answers \$num_answers\] + } else { + set new_mc_id \$mc_id + } db_dml update_item_type {} } set count 0 - foreach i \[lsort -integer \[array names choice\]\] { - if {!\[empty_string_p \$choice(\$i)\]} { - incr count - set choice_id \[as::item_choice::new -mc_id \$mc_id \\ + if {\[empty_string_p \$mc_id\]} { + foreach i \[lsort -integer \[array names choice\]\] { + if {!\[empty_string_p \$choice(\$i)\]} { + incr count + set choice_id \[as::item_choice::new -mc_id \$new_mc_id \\ -title \$choice(\$i) \\ -numeric_value \"\" \\ -text_value \"\" \\ @@ -134,14 +148,19 @@ -correct_answer_p \[ad_decode \[info exists correct(\$i)\] 0 f t\] \\ -sort_order \$count \\ -percent_score \"\"\] + } } } } }" set after_submit "{ # now go to form to enter choice-specific data - ad_returnredirect \[export_vars -base \"item-add-mc-choices\" {assessment_id section_id as_item_id after mc_id display_type}\] + if {\[empty_string_p \$mc_id\]} { + ad_returnredirect \[export_vars -base \"item-add-mc-choices\" {assessment_id section_id as_item_id after mc_id display_type}\] + } else { + ad_returnredirect \[export_vars -base \"item-add-display-\$display_type\" {assessment_id section_id as_item_id after}\] + } ad_script_abort }"