Index: openacs-4/packages/assessment/www/asm-admin/item-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/asm-admin/item-add.tcl,v diff -u -r1.13 -r1.14 --- openacs-4/packages/assessment/www/asm-admin/item-add.tcl 18 Nov 2006 13:28:26 -0000 1.13 +++ openacs-4/packages/assessment/www/asm-admin/item-add.tcl 15 May 2007 20:14:17 -0000 1.14 @@ -7,6 +7,8 @@ assessment_id:integer section_id:integer after:integer + choice:optional,array + correct:optional,array } -properties { context:onevalue page_title:onevalue @@ -31,70 +33,132 @@ set boolean_options [list [list "[_ assessment.yes]" t] [list "[_ assessment.no]" f]] set type $assessment_data(type) -set data_types [list] -foreach data_type [list varchar text integer float date timestamp boolean content_type] { - lappend data_types [list "[_ assessment.data_type_$data_type]" $data_type] -} +#set data_types [list] +#foreach data_type [list varchar text integer float date timestamp boolean content_type] { +# lappend data_types [list "[_ assessment.data_type_$data_type]" $data_type] +#} -set item_types [list] -foreach item_type [db_list item_types {}] { - lappend item_types [list "[_ assessment.item_type_$item_type]" $item_type] -} - - -ad_form -name item_add -action item-add -export { assessment_id section_id after type} -html {enctype multipart/form-data} -form { +set item_types [as_item_type::get_item_types] +ns_log notice " +DB -------------------------------------------------------------------------------- +DB DAVE debugging /var/lib/aolserver/openacs-5-3/packages/assessment/www/asm-admin/item-add.tcl +DB -------------------------------------------------------------------------------- +DB item_types = '${item_types}' +DB --------------------------------------------------------------------------------" +ad_form -name item-add -action item-add -export { assessment_id section_id after type } -html {enctype multipart/form-data} -form { {as_item_id:key} - {question_text:richtext {label "[_ assessment.item_Question]"} {html {rows 9 cols 80 style {width: 100%}}} {help_text "[_ assessment.item_Question_help]"}} + {question_text:richtext,nospell {label "[_ assessment.item_Question]"} {html {rows 12 cols 80 style {width: 99%}}} {help_text "[_ assessment.item_Question_help]"}} } -if { $type > 1} { - ad_form -extend -name item_add -form {{description:text(textarea),optional {label "[_ assessment.Description]"} {html {rows 9 cols 80}} {help_text "[_ assessment.item_Description_help]"}} - } +if { $type ne "survey"} { +# ad_form -extend -name item-add -form {{description:text(textarea),optional {label "[_ assessment.Description]"} {html {rows 12 cols 80}} {help_text "[_ assessment.item_Description_help]"}} +# } } if {![empty_string_p [category_tree::get_mapped_trees $package_id]]} { - category::ad_form::add_widgets -container_object_id $package_id -categorized_object_id 0 -form_name item_add + category::ad_form::add_widgets -container_object_id $package_id -categorized_object_id 0 -form_name item-add } -if { $type > 1} { -ad_form -extend -name item_add -form { - {content:file,optional {label "[_ assessment.item_Content]"} {help_text "[_ assessment.item_Content_help]"}} - {field_name:text,optional,nospell {label "[_ assessment.Field_Name]"} {html {size 80 maxlength 500}} {help_text "[_ assessment.Field_Name_help]"}} - {field_code:text,optional,nospell {label "[_ assessment.Field_Code]"} {html {size 80 maxlength 500}} {help_text "[_ assessment.Field_Code_help]"}} +if { $type ne "survey"} { +ad_form -extend -name item-add -form { +# {content:file,optional {label "[_ assessment.item_Content]"} {help_text "[_ assessment.item_Content_help]"}} +# {field_name:text,optional,nospell {label "[_ assessment.Field_Name]"} {html {size 80 maxlength 500}} {help_text "[_ assessment.Field_Name_help]"}} +# {field_code:text,optional,nospell {label "[_ assessment.Field_Code]"} {html {size 80 maxlength 500}} {help_text "[_ assessment.Field_Code_help]"}} } } -ad_form -extend -name item_add -form { {required_p:text(select) {label "[_ assessment.Required]"} {options $boolean_options} {help_text "[_ assessment.item_Required_help]"}} +ad_form -extend -name item-add -form { {required_p:text(select) {label "[_ assessment.Required]"} {options $boolean_options} {help_text "[_ assessment.item_Required_help]"}} } -if { $type > 1} { -ad_form -extend -name item_add -form { - {feedback_right:richtext,optional {label "[_ assessment.Feedback_right]"} {html {rows 9 cols 80}} {help_text "[_ assessment.Feedback_right_help]"}} - {feedback_wrong:richtext,optional {label "[_ assessment.Feedback_wrong]"} {html {rows 9 cols 80}} {help_text "[_ assessment.Feedback_wrong_help]"}} - {max_time_to_complete:integer,optional,nospell {label "[_ assessment.time_for_completion]"} {html {size 10 maxlength 10}} {help_text "[_ assessment.item_time_help]"}} +if { $type ne "survey"} { +ad_form -extend -name item-add -form { {points:integer,optional,nospell {label "[_ assessment.points_item]"} {html {size 10 maxlength 10}} {help_text "[_ assessment.points_item_help]"}} + {feedback_right:richtext,optional,nospell {label "[_ assessment.Feedback_right]"} {html {rows 12 cols 80 style {width: 99%}}} {help_text "[_ assessment.Feedback_right_help]"}} + {feedback_wrong:richtext,optional,nospell {label "[_ assessment.Feedback_wrong]"} {html {rows 12 cols 80 style {width: 99%}}} {help_text "[_ assessment.Feedback_wrong_help]"}} +# {max_time_to_complete:integer,optional,nospell {label "[_ assessment.time_for_completion]"} {html {size 10 maxlength 10}} {help_text "[_ assessment.item_time_help]"}} +# {points:integer,optional,nospell {label "[_ assessment.points_item]"} {html {size 10 maxlength 10}} {help_text "[_ assessment.points_item_help]"}} + {field_code:text(hidden),optional} + {field_name:text(hidden),optional} + {max_time_to_complete:text(hidden),optional} + {validate_block:text(hidden),optional} + {content:text(hidden),optional} + {description:text(hidden),optional {value ""}} + {data_type:text(hidden),optional {value ""}} } } else { -ad_form -extend -name item_add -form { - {description:text(hidden) {value ""}} - {content:text(hidden) {value ""}} +ad_form -extend -name item-add -form { + {description:text(hidden),optional {value ""}} + {content:text(hidden),optional {value ""}} {field_name:text,optional,nospell {label "[_ assessment.Field_Name]"} {html {size 80 maxlength 500}} {help_text "[_ assessment.Field_Name_help]"}} - {field_code:text(hidden) {value ""}} - {feedback_right:text(hidden) {value ""}} - {feedback_wrong:text(hidden) {value ""}} - {max_time_to_complete:text(hidden) {value ""}} - {points:text(hidden) {value ""}} - {data_type:text(hidden) {value ""}} - + {field_code:text(hidden),optional {value ""}} + {feedback_right:text(hidden),optional {value ""}} + {feedback_wrong:text(hidden),optional {value ""}} + {max_time_to_complete:text(hidden),optional {value ""}} + {points:text(hidden),optional {value ""}} + {data_type:text(hidden),optional {value ""}} + {validate_block:text(textarea),optional \ + {label "[_ assessment.Validation_Block]"} \ + {help_text "[_ assessment.lt_This_field_is_used_to]"} \ + {html {cols 70 rows 6}}} } } -if { $type > 1} { -ad_form -extend -name item_add -form { - {data_type:text(select) {label "[_ assessment.Data_Type]"} {options $data_types} {help_text "[_ assessment.Data_Type_help]"}}} +if { $type ne "survey"} { + #ad_form -extend -name item-add -form { + # {data_type:text(select) {label "[_ assessment.Data_Type]"} {options $data_types} {help_text "[_ assessment.Data_Type_help]"}}} } -ad_form -extend -name item_add -form { - {item_type:text(select) {label "[_ assessment.Item_Type]"} {options $item_types} {help_text "[_ assessment.Item_Type_help]"}} - {num_choices:integer,optional,nospell {label "[_ assessment.Num_Choices]"} {html {size 5 maxlength 3}} {help_text "[_ assessment.Num_Choices_help]"}} - {validate_block:text(textarea),optional {label "[_ assessment.Validation_Block]"} {help_text "[_ assessment.lt_This_field_is_used_to]"} {html {cols 70 rows 6}}} -} -new_request { + +ad_form -extend -name item-add -form { + {item_type:text(radio) {label "[_ assessment.Item_Type]"} {options $item_types} {help_text "[_ assessment.Item_Type_help]"}} + # {validate_block:text(textarea),optional {label "[_ assessment.Validation_Block]"} {help_text "[_ assessment.lt_This_field_is_used_to]"} {html {cols 70 rows 6}}} + {num_choices:text(hidden)} +} + + + +############################################################################## +# Multiple Choice Section +############################################################################## + +ad_form -extend -name item-add -form { + {add_another_choice:text(submit) {label "[_ assessment.Add_another_choice]"}} +} +if {[template::form::is_submission item-add] \ + && [template::element::get_value item-add add_another_choice] \ + eq [_ assessment.Add_another_choice]} { + set num_choices [element::get_value item-add num_choices] + incr num_choices + element::set_value item-add num_choices $num_choices +} + +if {![template::form::is_submission item-add] \ + && ![info exists num_choices]} { + set num_choices 5 +} else { + set num_choices [template::element::get_value item-add num_choices] +} + +template::multirow create choice_elements id +for {set i 1} {$i <=$num_choices} {incr i} { + template::multirow append choice_elements ${i} +} +as::item_type_mc::add_choices_to_form \ + -form_id item-add \ + -num_choices $num_choices \ + -choice_array_name choice \ + -correct_choice_array_name correct + +# for open questions +ad_form -extend -name item-add -form { + {reference_answer:text(textarea),optional {label "[_ assessment.oq_Reference_Answer]"} {html {rows 5 style {width:95%}}} {help_text "[_ assessment.oq_Reference_Answer_help]"}} +} + +ad_form -extend -name item-add -form { + {formbutton_ok:text(submit) {label "[_ assessment.Save_and_finish]"}} + {formbutton_add_another_question:text(submit) {label "[_ assessment.Save_and_add_another_question]"}} +} + +ad_form -extend -name item-add -validate { + {item_type {$item_type ne "mc" || [array size choice] > [llength [lsearch -all -exact [array get choice] ""]]} "Please enter at least one choice for multiple choice question."} +} +ad_form -extend -name item-add -new_request { set name "" set question_text "" set description "" @@ -105,30 +169,47 @@ set feedback_wrong "" set max_time_to_complete "" set points "" - set data_type "varchar" - set item_type "sa" - set num_choices 10 - if { $type == 1} { - set num_choices 3 - } + set num_choices 5 + set ms_label "Choose all that apply" } -on_submit { set category_ids [category::ad_form::get_categories -container_object_id $package_id] if {[empty_string_p $points]} { set points 0 } -} -new_data { - if {[string eq $item_type "sa"]} { + + + if {![exists_and_not_null formbutton_add_another_choice]} { + # map display types to data types + switch -exact $item_type { + sa { set data_type "varchar" - } elseif {[string eq $item_type "oq"]} { + set display_type "tb" + } + oq { set data_type "text" - } elseif {[string eq $item_type "mc"]} { + set display_type "ta" + } + mc { set data_type "varchar" - } elseif {[string eq $item_type "fu"]} { + set display_type "rb" + } + ms { + #multiple select is just multiple choice with checkboxes + set item_type "mc" + set data_type "varchar" + set display_type "cb" + } + fu { set data_type "file" - } + set display_type "fu" + } + } set question_text [template::util::richtext::get_property content $question_text] + set feedback_right [template::util::richtext::get_property content $feedback_right] + set feedback_wrong [template::util::richtext::get_property content $feedback_wrong] db_transaction { if {![db_0or1row item_exists {}]} { + set as_item_id [as::item::new \ -item_item_id $as_item_id \ -title $question_text \ @@ -186,11 +267,58 @@ set content_rev_id [cr_import_content -title $filename $folder_id $tmp_filename $n_bytes $file_mimetype [as::item::generate_unique_name]] as::item_rels::new -item_rev_id $as_item_id -target_rev_id $content_rev_id -type as_item_content_rel } + # check question type + set title [string range $question_text 0 999] + switch -exact $item_type { + mc { + as::item_type_mc::add_to_assessment \ + -assessment_id $assessment_id \ + -section_id $section_id \ + -as_item_id $as_item_id \ + -choices [array get choice] \ + -correct_choices [array get correct] \ + -after $after \ + -title $title\ + -display_type $display_type + } + oq { + as::item_type_oq::add_to_assessment \ + -assessment_id $assessment_id \ + -section_id $section_id \ + -as_item_id $as_item_id \ + -after $after \ + -title $title + } + sa { + as::item_type_sa::add_to_assessment \ + -assessment_id $assessment_id \ + -section_id $section_id \ + -as_item_id $as_item_id \ + -after $after \ + -title $title + } + fu { + as::item_type_fu::add_to_assessment \ + -assessment_id $assessment_id \ + -section_id $section_id \ + -as_item_id $as_item_id \ + -after $after \ + -title $title + } + } } +} } -after_submit { - # now go to item-type specific form (i.e. multiple choice) - ad_returnredirect [export_vars -base "item-add-$item_type" {assessment_id section_id as_item_id after num_choices}] - ad_script_abort + if {![exists_and_not_null formbutton_add_another_question] \ + && ![exists_and_not_null formbutton_add_another_choice]} { + ad_returnredirect "[export_vars -base questions {assessment_id}]\&#Q$as_item_id" + + ad_script_abort + } elseif {[exists_and_not_null formbutton_add_another_question]} { + set after [expr {$after + 1}] + ad_returnredirect "[export_vars -base item-add {after assessment_id section_id}]\#Q$as_item_id" + } } + ad_return_template