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.5 -r1.6 --- openacs-4/packages/assessment/www/asm-admin/item-add-mc.tcl 15 Mar 2005 22:46:15 -0000 1.5 +++ openacs-4/packages/assessment/www/asm-admin/item-add-mc.tcl 29 Mar 2005 10:53:35 -0000 1.6 @@ -34,9 +34,8 @@ set boolean_options [list [list "[_ assessment.yes]" t] [list "[_ assessment.no]" f]] set correct_options [list [list "[_ assessment.yes]" t]] +set add_existing_link [export_vars -base "item-add-mc-existing" {assessment_id section_id as_item_id after}] -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] @@ -51,7 +50,6 @@ {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 @@ -69,7 +67,9 @@ } else { append ad_form_code "\{correct.$i:text(checkbox),optional \{label \"[_ assessment.Correct_Answer_Choice] $i\"\} \{options \$correct_options\} \{help_text \"[_ assessment.Correct_Answer_help]\"\}\}\n" } - lappend validate_list "correct.$i {\$count_correct > 0} \"\[_ assessment.one_correct_choice_req\]\"" + if {[exists_and_not_null num_correct_answers] && $num_correct_answers > 0} { + lappend validate_list "correct.$i {\$count_correct > 0} \"\[_ assessment.one_correct_choice_req\]\"" + } } append ad_form_code "\}" if {[exists_and_not_null mc_id]} { @@ -99,20 +99,16 @@ set edit_data "{ db_transaction { if {!\[db_0or1row item_type {}\] || \$object_type != \"as_item_type_mc\"} { - if {\[empty_string_p \$mc_id\]} { - set new_mc_id \[as::item_type_mc::new \\ + set 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 \$new_mc_id -type as_item_type_rel + as::item_rels::new -item_rev_id \$as_item_id -target_rev_id \$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\] @@ -121,27 +117,22 @@ } else { # old mc item type existing set as_item_id \[as::item::new_revision -as_item_id \$as_item_id\] - if {\[empty_string_p \$mc_id\]} { - set new_mc_id \[as::item_type_mc::edit \\ + set 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 - 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 \\ + 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 \\ -title \$choice(\$i) \\ -numeric_value \"\" \\ -text_value \"\" \\ @@ -151,19 +142,14 @@ -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 - 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_returnredirect \[export_vars -base \"item-add-mc-choices\" {assessment_id section_id as_item_id after mc_id display_type}\] ad_script_abort }"