@@ -67,13 +67,12 @@- - - + @items.name@: #assessment.Question# @items.rownum@: * @items.title;noquote@ + @items.content;noquote@ Index: openacs-4/packages/assessment/www/assessment.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/Attic/assessment.tcl,v diff -u -r1.16 -r1.17 --- openacs-4/packages/assessment/www/assessment.tcl 26 Dec 2004 15:07:44 -0000 1.16 +++ openacs-4/packages/assessment/www/assessment.tcl 7 Jan 2005 16:10:44 -0000 1.17 @@ -9,6 +9,8 @@ {session_id:integer,optional ""} {section_order:integer,optional ""} {item_order:integer,optional ""} + {as_item_id ""} + response_to_item:array,optional,multiple,html } -properties { session_id context:onevalue @@ -57,47 +59,46 @@ # get all items of section in correct order - set item_list [as::section::items -section_id $section_id -session_id $session_id -sort_order_type $display(sort_order_type)] + set item_list [as::section::items -section_id $section_id -session_id $session_id -sort_order_type $display(sort_order_type) -num_items $section(num_items)] if {![empty_string_p $item_order]} { # show next items on section page set item_list [lreplace $item_list 0 [expr $item_order-1]] } - set old_item_order $item_order - set old_section_order $section_order + if {![empty_string_p $display(num_items)]} { if {[llength $item_list] > $display(num_items)} { # next page: more items of this section if {[empty_string_p $item_order]} { - set item_order 0 + set new_item_order 0 } - set item_order [expr $item_order + $display(num_items)] + set new_item_order [expr $item_order + $display(num_items)] # show only a few items per page set item_list [lreplace $item_list $display(num_items) end] } else { # next page: next section - set item_order "" - incr section_order + set new_item_order "" + set new_section_order [expr $section_order + 1] } } else { # next page: next section - incr section_order + set new_section_order [expr $section_order + 1] } if {$section_order == [llength $section_list]} { - set section_order "" + set new_section_order "" } # form for display an assessment with sections and items - ad_form -name show_item_form -action process-response -html {enctype multipart/form-data} -export {assessment_id section_id section_order item_order} -form { - { session_id:text {value $session_id} } + ad_form -name show_item_form -action assessment -html {enctype multipart/form-data} -export {assessment_id section_id section_order item_order} -form { + { session_id:text(hidden) {value $session_id} } } - multirow create items as_item_id name title description subtext required_p max_time_to_complete presentation_type html submitted_p + multirow create items as_item_id name title description subtext required_p max_time_to_complete presentation_type html submitted_p content foreach one_item $item_list { - util_unlist $one_item as_item_id name title description subtext required_p max_time_to_complete + util_unlist $one_item as_item_id name title description subtext required_p max_time_to_complete content_rev_id content_filename content_type set default_value "" set submitted_p f @@ -106,7 +107,7 @@ if {$assessment_data(reuse_responses_p) == "t"} { set default_value [as::item_data::get -subject_id $user_id -as_item_id $as_item_id] } - set presentation_type [as::item_form::add_item_to_form -name show_item_form -session_id $session_id -section_id $section_id -item_id $as_item_id -default_value $default_value] + set presentation_type [as::item_form::add_item_to_form -name show_item_form -session_id $session_id -section_id $section_id -item_id $as_item_id -default_value $default_value -required_p $required_p] } else { # submit each item seperately set default_value [as::item_data::get -subject_id $user_id -as_item_id $as_item_id -session_id $session_id] @@ -121,12 +122,35 @@ set default_value [as::item_data::get -subject_id $user_id -as_item_id $as_item_id] } } - ad_form -name show_item_form_$as_item_id -mode $mode -action process-response -html {enctype multipart/form-data} -export {assessment_id section_id} -form { - { session_id:text {value $session_id} } - { section_order:text {value $old_section_order} } - { item_order:text {value $old_item_order} } + ad_form -name show_item_form_$as_item_id -mode $mode -action assessment -html {enctype multipart/form-data} -export {assessment_id section_id section_order item_order} -form { + { session_id:text(hidden) {value $session_id} } } - set presentation_type [as::item_form::add_item_to_form -name show_item_form_$as_item_id -session_id $session_id -section_id $section_id -item_id $as_item_id -default_value $default_value] + set presentation_type [as::item_form::add_item_to_form -name show_item_form_$as_item_id -session_id $session_id -section_id $section_id -item_id $as_item_id -default_value $default_value -required_p $required_p] + + # process single submit + ad_form -extend -name show_item_form_$as_item_id -on_submit { + db_transaction { + db_dml session_updated {} + + set response_item_id $as_item_id + db_1row process_item_type {} + set item_type [string range $item_type end-1 end] + if {![info exists response_to_item($as_item_id)]} { + set response_to_item($as_item_id) "" + } + + as::item_type_$item_type\::process -type_id $item_type_id -session_id $session_id -as_item_id $response_item_id -subject_id $user_id -response $response_to_item($as_item_id) -max_points $points + } + } -after_submit { + if {![empty_string_p $section_order]} { + ad_returnredirect [export_vars -base assessment {assessment_id session_id section_order item_order}] + ad_script_abort + } else { + db_dml session_finished {} + ad_returnredirect [export_vars -base finish {session_id assessment_id}] + ad_script_abort + } + } } # Fill in the blank item. Replace all that appear in the title by an of type="text" @@ -135,8 +159,40 @@ } set max_time_to_complete [as::assessment::pretty_time -seconds $max_time_to_complete] - multirow append items $as_item_id $name $title $description $subtext $required_p $max_time_to_complete $presentation_type "" $submitted_p + multirow append items $as_item_id $name $title $description $subtext $required_p $max_time_to_complete $presentation_type "" $submitted_p [as::assessment::display_content -content_id $content_rev_id -filename $content_filename -content_type $content_type] } + + if {$display(submit_answer_p) != "t"} { + foreach one_item $item_list { + util_unlist $one_item as_item_id + append validate_list "\{response_to_item.$as_item_id \{\[exist_and_not_null \$response_to_item.$as_item_id\]\} \"Answer missing\"\}\n" + } + # process multiple submit + eval ad_form -extend -name show_item_form -validate "{$validate_list}" + ad_form -extend -name show_item_form -on_submit { + db_transaction { + db_dml session_updated {} + + foreach response_item_id [array names response_to_item] { + db_1row process_item_type {} + set item_type [string range $item_type end-1 end] + + as::item_type_$item_type\::process -type_id $item_type_id -session_id $session_id -as_item_id $response_item_id -subject_id $user_id -response $response_to_item($response_item_id) -max_points $points + } + } + } -after_submit { + if {![empty_string_p $new_section_order]} { + set section_order $new_section_order + set item_order $new_item_order + ad_returnredirect [export_vars -base assessment {assessment_id session_id section_order item_order}] + ad_script_abort + } else { + db_dml session_finished {} + ad_returnredirect [export_vars -base finish {session_id assessment_id}] + ad_script_abort + } + } + } } ad_return_template Index: openacs-4/packages/assessment/www/assessment.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/Attic/assessment.xql,v diff -u -r1.5 -r1.6 --- openacs-4/packages/assessment/www/assessment.xql 22 Dec 2004 20:52:17 -0000 1.5 +++ openacs-4/packages/assessment/www/assessment.xql 7 Jan 2005 16:10:44 -0000 1.6 @@ -5,7 +5,7 @@ select s.section_id, cr.title, cr.description, s.instructions, - m.max_time_to_complete, s.display_type_id + m.max_time_to_complete, s.display_type_id, s.num_items from cr_revisions cr, as_sections s, as_assessment_section_map m where cr.revision_id = s.section_id and s.section_id = :section_id @@ -26,4 +26,19 @@ ++ + Index: openacs-4/packages/assessment/www/finish.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/finish.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/assessment/www/finish.adp 7 Jan 2005 16:10:44 -0000 1.1 @@ -0,0 +1,8 @@ ++ + select o.object_type as item_type, r.target_rev_id as item_type_id, + m.points + from acs_objects o, as_item_rels r, as_item_section_map m + where r.item_rev_id = :response_item_id + and r.rel_type = 'as_item_type_rel' + and o.object_id = r.target_rev_id + and m.as_item_id = r.item_rev_id + and m.section_id = :section_id + + ++ #assessment.Response_Submitted# +@context_bar;noquote@ +++ Index: openacs-4/packages/assessment/www/finish.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/finish.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/assessment/www/finish.tcl 7 Jan 2005 16:10:44 -0000 1.1 @@ -0,0 +1,17 @@ +ad_page_contract { + + Insert user response into database. + This page receives an input for each item named + response_to_item.$item_id + + @author eperez@it.uc3m.es + @date 2004-09-12 +} { + session_id:integer,notnull + assessment_id:integer,notnull +} + +set context_bar [list] +set user_id [ad_conn user_id] + +ad_return_template Index: openacs-4/packages/assessment/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/index.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/assessment/www/index.tcl 17 Nov 2004 17:16:08 -0000 1.5 +++ openacs-4/packages/assessment/www/index.tcl 7 Jan 2005 16:10:44 -0000 1.6 @@ -13,6 +13,7 @@ set context [list "[_ assessment.Show_Assessments]"] set package_id [ad_conn package_id] +set folder_id [as::assessment::folder_id -package_id $package_id] # create a list with all assessments and their sessions template::list::create \ Index: openacs-4/packages/assessment/www/index.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/index.xql,v diff -u -r1.5 -r1.6 --- openacs-4/packages/assessment/www/index.xql 29 Dec 2004 10:19:07 -0000 1.5 +++ openacs-4/packages/assessment/www/index.xql 7 Jan 2005 16:10:44 -0000 1.6 @@ -1,15 +1,18 @@#assessment.Response_Submitted#
+ +- Index: openacs-4/packages/assessment/www/session.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/session.tcl,v diff -u -r1.29 -r1.30 --- openacs-4/packages/assessment/www/session.tcl 26 Dec 2004 15:07:44 -0000 1.29 +++ openacs-4/packages/assessment/www/session.tcl 7 Jan 2005 16:10:44 -0000 1.30 @@ -21,7 +21,6 @@ ad_script_abort } -set assessment_rev_id $assessment_data(assessment_rev_id) set session_user_url [acs_community_member_url -user_id $subject_id] # get start and end times Index: openacs-4/packages/assessment/www/session.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/session.xql,v diff -u -r1.15 -r1.16 --- openacs-4/packages/assessment/www/session.xql 24 Dec 2004 15:32:38 -0000 1.15 +++ openacs-4/packages/assessment/www/session.xql 7 Jan 2005 16:10:44 -0000 1.16 @@ -3,8 +3,8 @@- +- select cr.item_id as assessment_id, cr.title, cr.description - from as_assessments a, cr_revisions cr, cr_items ci - where a.assessment_id = cr.revision_id - and cr.revision_id = ci.latest_revision - and exists (select 1 from as_assessment_section_map asm - where asm.assessment_id = a.assessment_id) - -+ + select cr.item_id as assessment_id, cr.title, cr.description + from as_assessments a, cr_revisions cr, cr_items ci + where a.assessment_id = cr.revision_id + and cr.revision_id = ci.latest_revision + and ci.parent_id = :folder_id + and exists (select 1 + from as_assessment_section_map asm, as_item_section_map ism + where asm.assessment_id = a.assessment_id + and ism.section_id = asm.section_id) + ++ - select r.item_id as assessment_id, s.subject_id, - p.first_names, p.last_name + select r.item_id as assessment_id, s.assessment_id as assessment_rev_id, + s.subject_id, p.first_names, p.last_name from as_sessions s, cr_revisions r, persons p where s.session_id = :session_id and r.revision_id = s.assessment_id Index: openacs-4/packages/assessment/www/admin/assessment-form.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/assessment-form.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/assessment/www/admin/assessment-form.tcl 22 Dec 2004 20:52:18 -0000 1.5 +++ openacs-4/packages/assessment/www/admin/assessment-form.tcl 7 Jan 2005 16:10:44 -0000 1.6 @@ -5,18 +5,19 @@ @cvs-id $Id: } { assessment_id:integer,optional + {__new_p 0} } -properties { context_bar:onevalue page_title:onevalue } -if {[info exists assessment_id]} { - set page_title [_ assessment.Edit_Assessment] +if {![info exists assessment_id] || $__new_p} { + set page_title [_ assessment.New_Assessment2] set _assessment_id 0 - db_0or1row rev_id_from_item_id {} } else { - set page_title [_ assessment.New_Assessment2] + set page_title [_ assessment.Edit_Assessment] set _assessment_id 0 + db_0or1row rev_id_from_item_id {} } set context_bar [ad_context_bar $page_title] @@ -31,8 +32,21 @@ ad_form -name assessment_form -action assessment-form -form { {assessment_id:key} +} + +if {[info exists assessment_id]} { + ad_form -extend -name assessment_form -form { + {name:text(inform) {label "[_ assessment.Name]"} {html {size 80 maxlength 1000}} {help_text "[_ assessment.assessment_Name_help]"}} + } +} else { + ad_form -extend -name assessment_form -form { + {name:text,optional {label "[_ assessment.Name]"} {html {size 80 maxlength 1000}} {help_text "[_ assessment.assessment_Name_help]"}} + } +} + +ad_form -extend -name assessment_form -form { {title:text {label "[_ assessment.Title]"} {html {size 80 maxlength 1000}} {help_text "[_ assessment.as_Title_help]"}} - {description:text(textarea) {label "[_ assessment.Description]"} {html {rows 5 cols 80}} {help_text "[_ assessment.as_Description_help]"}} + {description:text(textarea),optional {label "[_ assessment.Description]"} {html {rows 5 cols 80}} {help_text "[_ assessment.as_Description_help]"}} } if {![empty_string_p [category_tree::get_mapped_trees $package_id]]} { @@ -58,6 +72,7 @@ {show_feedback:text(select),optional {label "[_ assessment.Show_Feedback]"} {options $feedback_options} {help_text "[_ assessment.as_Feedback_help]"}} {section_navigation:text(select),optional {label "[_ assessment.Section_Navigation]"} {options $navigation_options} {help_text "[_ assessment.as_Navigation_help]"}} } -new_request { + set name "" set title "" set description "" set instructions "" @@ -86,6 +101,8 @@ if {![empty_string_p $end_time]} { set end_time [util::date::acquire clock [clock scan $end_time]] } +} -validate { + {name {[as::assessment::unique_name -name $name -new_p $__new_p]} "[_ assessment.name_used]"} } -on_submit { if {$start_time == "NULL"} { set start_time "" @@ -97,6 +114,7 @@ } -new_data { db_transaction { set assessment_rev_id [as::assessment::new \ + -name $name \ -title $title \ -description $description \ -instructions $instructions \ Index: openacs-4/packages/assessment/www/admin/assessment-form.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/assessment-form.xql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/assessment/www/admin/assessment-form.xql 22 Dec 2004 20:52:18 -0000 1.4 +++ openacs-4/packages/assessment/www/admin/assessment-form.xql 7 Jan 2005 16:10:45 -0000 1.5 @@ -4,7 +4,7 @@ - select cr.title, cr.description, a.instructions, a.run_mode, + select ci.name, cr.title, cr.description, a.instructions, a.run_mode, a.anonymous_p, a.secure_access_p, a.reuse_responses_p, a.show_item_name_p, a.entry_page, a.exit_page, a.consent_page, a.return_url, a.number_tries, a.wait_between_tries, a.time_for_response, a.show_feedback, a.section_navigation, Index: openacs-4/packages/assessment/www/admin/item-add-mc-choices.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/item-add-mc-choices.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/assessment/www/admin/item-add-mc-choices.tcl 29 Dec 2004 09:07:39 -0000 1.3 +++ openacs-4/packages/assessment/www/admin/item-add-mc-choices.tcl 7 Jan 2005 16:10:45 -0000 1.4 @@ -11,6 +11,8 @@ mc_id:integer display_type feedback:array,optional + fixed_pos:array,optional + answer_val:array,optional percent:array,optional selected:array,optional } -properties { @@ -28,12 +30,13 @@ ad_script_abort } +set package_id [ad_conn package_id] set page_title [_ assessment.add_item_type_mc_choices] set context_bar [ad_context_bar [list [export_vars -base one-a {assessment_id}] $assessment_data(title)] $page_title] set selected_options [list [list "[_ assessment.yes]" t]] -ad_form -name item_add_mc_choices -action item-add-mc-choices -export { assessment_id section_id after mc_id display_type } -form { +ad_form -name item_add_mc_choices -action item-add-mc-choices -export { assessment_id section_id after mc_id display_type } -html {enctype multipart/form-data} -form { {as_item_id:key} } @@ -47,6 +50,9 @@ append ad_form_code "\{infotxt.$choice_id:text(inform) \{label \"[_ assessment.Choice]\"\} \{value \"$title \"\}\}\n" } append ad_form_code "\{selected.$choice_id:text(checkbox),optional \{label \"[_ assessment.Default_Selected]\"\} \{options \$selected_options\} \{help_text \"[_ assessment.Default_Selected_help]\"\}\}\n" + append ad_form_code "\{fixed_pos.$choice_id:text,optional \{label \"[_ assessment.Fixed_Position]\"\} \{html \{size 5 maxlength 5\}\} \{help_text \"[_ assessment.choice_Fixed_Position_help]\"\}\}\n" + append ad_form_code "\{answer_val.$choice_id:text,optional \{label \"[_ assessment.Answer_Value]\"\} \{html \{size 80 maxlength 500\}\} \{help_text \"[_ assessment.Answer_Value_help]\"\}\}\n" + append ad_form_code "\{content_$choice_id:file,optional \{label \"[_ assessment.choice_Content]\"\} \{help_text \"[_ assessment.choice_Content_help]\"\}\}\n" append ad_form_code "\{feedback.$choice_id:text(textarea),optional \{label \"[_ assessment.Feedback]\"\} \{html \{rows 8 cols 80\}\} \{help_text \"[_ assessment.choice_Feedback_help]\"\}\}\n" if {$correct_answer_p == "t"} { set default_percent "\$percentage" @@ -63,12 +69,40 @@ ad_form -extend -name item_add_mc_choices -edit_request { } -edit_data { + set max_file_size 10000000 + # [ad_parameter MaxAttachmentSize] + set pretty_max_size [util_commify_number $max_file_size] + set folder_id [as::assessment::folder_id -package_id $package_id] + db_transaction { set count 0 foreach choice_id [array names feedback] { set feedback_text $feedback($choice_id) set selected_p [ad_decode [info exists selected($choice_id)] 0 f t] set percent_score $percent($choice_id) + set fixed_position $fixed_pos($choice_id) + set answer_value $answer_val($choice_id) + + eval set content "\$content_$choice_id" + if {![empty_string_p $content]} { + set filename [lindex $content 0] + set tmp_filename [lindex $content 1] + set file_mimetype [lindex $content 2] + set n_bytes [file size $tmp_filename] + + if { $n_bytes > $max_file_size && $max_file_size > 0 } { + ad_return_complaint 1 "[_ assessment.file_too_large]" + return + } + if { $n_bytes == 0 } { + ad_return_complaint 1 "[_ assessment.file_zero_size]" + return + } + set content_rev_id [cr_import_content -package_id $package_id -title $filename $folder_id $tmp_filename $n_bytes $file_mimetype [exec uuidgen]] + } else { + set content_rev_id "" + } + db_dml update_choice_data {} } } Index: openacs-4/packages/assessment/www/admin/item-add-mc-choices.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/item-add-mc-choices.xql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/assessment/www/admin/item-add-mc-choices.xql 5 Dec 2004 17:11:59 -0000 1.1 +++ openacs-4/packages/assessment/www/admin/item-add-mc-choices.xql 7 Jan 2005 16:10:45 -0000 1.2 @@ -19,7 +19,10 @@ update as_item_choices set feedback_text = :feedback_text, selected_p = :selected_p, - percent_score = :percent_score + percent_score = :percent_score, + fixed_position = :fixed_position, + text_value = :answer_value, + content_value = :content_rev_id where choice_id = :choice_id Index: openacs-4/packages/assessment/www/admin/item-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/item-add.tcl,v diff -u -r1.7 -r1.8 --- openacs-4/packages/assessment/www/admin/item-add.tcl 29 Dec 2004 10:19:08 -0000 1.7 +++ openacs-4/packages/assessment/www/admin/item-add.tcl 7 Jan 2005 16:10:45 -0000 1.8 @@ -39,7 +39,7 @@ } -ad_form -name item_add -action item-add -export { assessment_id section_id after } -form { +ad_form -name item_add -action item-add -export { assessment_id section_id after } -html {enctype multipart/form-data} -form { {as_item_id:key} {name:text,optional {label "[_ assessment.Name]"} {html {size 80 maxlength 1000}} {help_text "[_ assessment.item_Name_help]"}} {title:text(textarea) {label "[_ assessment.item_Title]"} {html {rows 3 cols 80 maxlength 1000}} {help_text "[_ assessment.item_Title_help]"}} @@ -51,6 +51,7 @@ } ad_form -extend -name item_add -form { + {content:file,optional {label "[_ assessment.item_Content]"} {help_text "[_ assessment.item_Content_help]"}} {subtext:text,optional {label "[_ assessment.Subtext]"} {html {size 80 maxlength 500}} {help_text "[_ assessment.item_Subtext_help]"}} {field_code:text,optional {label "[_ assessment.Field_Code]"} {html {size 80 maxlength 500}} {help_text "[_ assessment.Field_Code_help]"}} {required_p:text(select) {label "[_ assessment.Required]"} {options $boolean_options} {help_text "[_ assessment.item_Required_help]"}} @@ -73,6 +74,8 @@ set points "" set data_type "varchar" set item_type "sa" +} -validate { + {name {[as::assessment::unique_name -name $name -new_p 1]} "[_ assessment.name_used]"} } -on_submit { set category_ids [category::ad_form::get_categories -container_object_id $package_id] } -new_data { @@ -93,6 +96,29 @@ if {[exists_and_not_null category_ids]} { category::map_object -object_id $as_item_id $category_ids } + + if {![empty_string_p $content]} { + set filename [lindex $content 0] + set tmp_filename [lindex $content 1] + set file_mimetype [lindex $content 2] + set n_bytes [file size $tmp_filename] + set max_file_size 10000000 + # [ad_parameter MaxAttachmentSize] + set pretty_max_size [util_commify_number $max_file_size] + + if { $n_bytes > $max_file_size && $max_file_size > 0 } { + ad_return_complaint 1 "[_ assessment.file_too_large]" + return + } + if { $n_bytes == 0 } { + ad_return_complaint 1 "[_ assessment.file_zero_size]" + return + } + + set folder_id [as::assessment::folder_id -package_id $package_id] + set content_rev_id [cr_import_content -package_id $package_id -title $filename $folder_id $tmp_filename $n_bytes $file_mimetype [exec uuidgen]] + as::item_rels::new -item_rev_id $as_item_id -target_rev_id $content_rev_id -type as_item_content_rel + } } } -after_submit { # now go to item-type specific form (i.e. multiple choice) Index: openacs-4/packages/assessment/www/admin/item-edit-general.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/item-edit-general.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/assessment/www/admin/item-edit-general.tcl 29 Dec 2004 09:07:39 -0000 1.4 +++ openacs-4/packages/assessment/www/admin/item-edit-general.tcl 7 Jan 2005 16:10:45 -0000 1.5 @@ -35,18 +35,25 @@ } -ad_form -name item_edit_general -action item-edit-general -export { assessment_id section_id } -form { +ad_form -name item_edit_general -action item-edit-general -export { assessment_id section_id } -html {enctype multipart/form-data} -form { {as_item_id:key} {name:text(inform) {label "[_ assessment.Name]"} {html {size 80 maxlength 1000}} {help_text "[_ assessment.item_Name_help]"}} {title:text {label "[_ assessment.Title]"} {html {size 80 maxlength 1000}} {help_text "[_ assessment.item_Title_help]"}} - {description:text(textarea) {label "[_ assessment.Description]"} {html {rows 5 cols 80}} {help_text "[_ assessment.item_Description_help]"}} + {description:text(textarea),optional {label "[_ assessment.Description]"} {html {rows 5 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 $as_item_id -form_name item_edit_general } +if {[db_0or1row get_item_content {}]} { + ad_form -extend -name item_edit_general -form { + {delete_content:text(checkbox),optional {label "[_ assessment.item_Delete_Content]"} {options {{{$content_name} t}} }} + } +} + ad_form -extend -name item_edit_general -form { + {content:file,optional {label "[_ assessment.item_Content]"} {help_text "[_ assessment.item_Content_help]"}} {subtext:text,optional {label "[_ assessment.Subtext]"} {html {size 80 maxlength 500}} {help_text "[_ assessment.item_Subtext_help]"}} {field_code:text,optional {label "[_ assessment.Field_Code]"} {html {size 80 maxlength 500}} {help_text "[_ assessment.Field_Code_help]"}} {required_p:text(select) {label "[_ assessment.Required]"} {options $boolean_options} {help_text "[_ assessment.item_Required_help]"}} @@ -59,6 +66,9 @@ {display_type:text(select) {label "[_ assessment.Display_Type]"} {options $display_types} {help_text "[_ assessment.Display_Type_help]"}} } -edit_request { db_1row general_item_data {} + if {[empty_string_p $data_type]} { + set data_type varchar + } set data_type_disp "[_ assessment.data_type_$data_type]" set display_type [string range [db_string get_display_type {}] end-1 end] } -on_submit { @@ -83,6 +93,31 @@ category::map_object -object_id $new_item_id $category_ids } + if {![empty_string_p $content]} { + set filename [lindex $content 0] + set tmp_filename [lindex $content 1] + set file_mimetype [lindex $content 2] + set n_bytes [file size $tmp_filename] + set max_file_size 10000000 + # [ad_parameter MaxAttachmentSize] + set pretty_max_size [util_commify_number $max_file_size] + + if { $n_bytes > $max_file_size && $max_file_size > 0 } { + ad_return_complaint 1 "[_ assessment.file_too_large]" + return + } + if { $n_bytes == 0 } { + ad_return_complaint 1 "[_ assessment.file_zero_size]" + return + } + + set folder_id [as::assessment::folder_id -package_id $package_id] + set content_rev_id [cr_import_content -package_id $package_id -title $filename $folder_id $tmp_filename $n_bytes $file_mimetype [exec uuidgen]] + db_dml update_item_content {} + } elseif {[info exists delete_content]} { + db_dml delete_item_content {} + } + set new_assessment_rev_id [as::assessment::new_revision -assessment_id $assessment_id] set new_section_id [as::section::new_revision -section_id $section_id] db_dml update_section_in_assessment {} Index: openacs-4/packages/assessment/www/admin/item-edit-general.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/item-edit-general.xql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/assessment/www/admin/item-edit-general.xql 22 Dec 2004 20:52:18 -0000 1.3 +++ openacs-4/packages/assessment/www/admin/item-edit-general.xql 7 Jan 2005 16:10:45 -0000 1.4 @@ -23,6 +23,19 @@+ ++ + select cr.title || ' (' || cr.content_length || ' bytes)' as content_name, + cr.revision_id as content_rev_id, cr.title as content_filename + from cr_revisions cr, as_item_rels r + where r.item_rev_id = :as_item_id + and r.target_rev_id = cr.revision_id + and r.rel_type = 'as_item_content_rel' + + ++ @@ -48,6 +61,27 @@ + + ++ + update as_item_rels + set target_rev_id = :content_rev_id + where item_rev_id = :new_item_id + and rel_type = 'as_item_content_rel' + + ++ ++ + delete from as_item_rels + where item_rev_id = :new_item_id + and rel_type = 'as_item_content_rel' + + ++ @@ -64,7 +98,8 @@ update as_item_section_map set as_item_id = :new_item_id, - points = :points + points = :points, + required_p = :required_p where section_id = :new_section_id and as_item_id = :as_item_id Index: openacs-4/packages/assessment/www/admin/item-edit-mc-choices-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/item-edit-mc-choices-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/assessment/www/admin/item-edit-mc-choices-oracle.xql 7 Jan 2005 16:10:45 -0000 1.1 @@ -0,0 +1,21 @@ + + + Index: openacs-4/packages/assessment/www/admin/item-edit-mc-choices-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/item-edit-mc-choices-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/assessment/www/admin/item-edit-mc-choices-postgresql.xql 7 Jan 2005 16:10:45 -0000 1.1 @@ -0,0 +1,21 @@ + ++ + oracle 8.1.6 + + ++ + select c.choice_id, r.title, c.correct_answer_p, c.feedback_text, + c.selected_p, c.percent_score, c.fixed_position, c.text_value, + c.content_value, r2.title as content_filename, + r2.title || ' (' || r2.content_length || ' bytes)' as content_name + from cr_revisions r, as_item_choices c, cr_revisions r2 + where c.content_value(+) = r2.revision_id + and r.revision_id = c.choice_id + and c.mc_id = :mc_id + order by c.sort_order + + ++ Index: openacs-4/packages/assessment/www/admin/item-edit-mc-choices.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/item-edit-mc-choices.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/assessment/www/admin/item-edit-mc-choices.tcl 29 Dec 2004 09:07:39 -0000 1.2 +++ openacs-4/packages/assessment/www/admin/item-edit-mc-choices.tcl 7 Jan 2005 16:10:45 -0000 1.3 @@ -9,6 +9,9 @@ as_item_id:integer mc_id:integer feedback:array,optional + fixed_pos:array,optional + answer_val:array,optional + delete_content:array,optional percent:array,optional selected:array,optional } -properties { @@ -26,12 +29,13 @@ ad_script_abort } +set package_id [ad_conn package_id] set page_title [_ assessment.edit_item_type_mc_choices] set context_bar [ad_context_bar [list [export_vars -base one-a {assessment_id}] $assessment_data(title)] [list [export_vars -base item-edit {assessment_id section_id as_item_id}] [_ assessment.edit_item]] $page_title] set selected_options [list [list "[_ assessment.yes]" t]] -ad_form -name item_edit_mc_choices -action item-edit-mc-choices -export { assessment_id section_id mc_id } -form { +ad_form -name item_edit_mc_choices -action item-edit-mc-choices -export { assessment_id section_id mc_id } -html {enctype multipart/form-data} -form { {as_item_id:key} } @@ -40,7 +44,7 @@ set count_correct 0 set choices [db_list_of_lists get_choices {}] foreach one_choice $choices { - util_unlist $one_choice choice_id title correct_answer_p feedback_text selected_p percent_score + util_unlist $one_choice choice_id title correct_answer_p feedback_text selected_p percent_score fixed_position answer_value content_rev_id content_filename content_name if {$correct_answer_p == "t"} { append ad_form_code "\{infotxt.$choice_id:text(inform) \{label \"[_ assessment.Choice]\"\} \{value \"$title \"\}\}\n" } else { @@ -51,6 +55,13 @@ } else { append ad_form_code "\{selected.$choice_id:text(checkbox),optional \{label \"[_ assessment.Default_Selected]\"\} \{options \$selected_options\} \{help_text \"[_ assessment.Default_Selected_help]\"\}\}\n" } + append ad_form_code "\{fixed_pos.$choice_id:text,optional \{label \"[_ assessment.Fixed_Position]\"\} \{html \{size 5 maxlength 5\}\} \{value \"$fixed_position\"\} \{help_text \"[_ assessment.choice_Fixed_Position_help]\"\}\}\n" + append ad_form_code "\{answer_val.$choice_id:text,optional \{label \"[_ assessment.Answer_Value]\"\} \{html \{size 80 maxlength 500\}\} \{value \"$answer_value\"\} \{help_text \"[_ assessment.Answer_Value_help]\"\}\}\n" + + if {![empty_string_p $content_rev_id]} { + append ad_form_code "\{delete_content.$choice_id:text(checkbox),optional \{label \"[_ assessment.choice_Delete_Content]\"\} \{options \{\{\{$content_name\} t\}\} \}\}\n" + } + append ad_form_code "\{content_$choice_id:file,optional \{label \"[_ assessment.choice_Content]\"\} \{help_text \"[_ assessment.choice_Content_help]\"\}\}\n" append ad_form_code "\{feedback.$choice_id:text(textarea),optional \{label \"[_ assessment.Feedback]\"\} \{html \{rows 8 cols 80\}\} \{value \{$feedback_text\}\} \{help_text \"[_ assessment.choice_Feedback_help]\"\}\}\n" if {$correct_answer_p == "t"} { set default_percent "\$percentage" @@ -67,21 +78,51 @@ ad_form -extend -name item_edit_mc_choices -edit_request { foreach one_choice $choices { - util_unlist $one_choice choice_id title correct_answer_p feedback_text selected_p percent_score + util_unlist $one_choice choice_id title correct_answer_p feedback_text selected_p percent_score fixed_position answer_value set feedback($choice_id) $feedback_text set percent($choice_id) $percent_score + set fixed_pos($choice_id) $fixed_position + set answer_val($choice_id) $answer_value if {$selected_p == "t"} { set selected($choice_id) t } } } -edit_data { db_transaction { + set max_file_size 10000000 + # [ad_parameter MaxAttachmentSize] + set pretty_max_size [util_commify_number $max_file_size] + set folder_id [as::assessment::folder_id -package_id $package_id] + set count 0 foreach choice_id [array names feedback] { set feedback_text $feedback($choice_id) set selected_p [ad_decode [info exists selected($choice_id)] 0 f t] set percent_score $percent($choice_id) + set fixed_position $fixed_pos($choice_id) + set answer_value $answer_val($choice_id) db_dml update_choice_data {} + + eval set content "\$content_$choice_id" + if {![empty_string_p $content]} { + set filename [lindex $content 0] + set tmp_filename [lindex $content 1] + set file_mimetype [lindex $content 2] + set n_bytes [file size $tmp_filename] + + if { $n_bytes > $max_file_size && $max_file_size > 0 } { + ad_return_complaint 1 "[_ assessment.file_too_large]" + return + } + if { $n_bytes == 0 } { + ad_return_complaint 1 "[_ assessment.file_zero_size]" + return + } + set content_rev_id [cr_import_content -package_id $package_id -title $filename $folder_id $tmp_filename $n_bytes $file_mimetype [exec uuidgen]] + db_dml update_choice_content {} + } elseif {[info exists delete_content($choice_id)]} { + db_dml delete_choice_content {} + } } } } -after_submit { Index: openacs-4/packages/assessment/www/admin/item-edit-mc-choices.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/item-edit-mc-choices.xql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/assessment/www/admin/item-edit-mc-choices.xql 8 Dec 2004 15:30:34 -0000 1.1 +++ openacs-4/packages/assessment/www/admin/item-edit-mc-choices.xql 7 Jan 2005 16:10:45 -0000 1.2 @@ -1,29 +1,38 @@+ + postgresql 7.1 + + ++ + select c.choice_id, r.title, c.correct_answer_p, c.feedback_text, + c.selected_p, c.percent_score, c.fixed_position, c.text_value, + c.content_value, r2.title as content_filename, + r2.title || ' (' || r2.content_length || ' bytes)' as content_name + from cr_revisions r, as_item_choices c + left outer join cr_revisions r2 on (c.content_value = r2.revision_id) + where r.revision_id = c.choice_id + and c.mc_id = :mc_id + order by c.sort_order + + +- Index: openacs-4/packages/assessment/www/admin/item-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/item-edit.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/assessment/www/admin/item-edit.tcl 29 Dec 2004 09:07:39 -0000 1.3 +++ openacs-4/packages/assessment/www/admin/item-edit.tcl 7 Jan 2005 16:10:45 -0000 1.4 @@ -42,6 +42,12 @@ category::ad_form::add_widgets -container_object_id $package_id -categorized_object_id $as_item_id -form_name item_edit } +if {[db_0or1row get_item_content {}]} { + ad_form -extend -name item_edit -form { + {content:text(inform),optional {label "[_ assessment.item_display_Content]"} {value {$content_name}} {help_text "[_ assessment.item_Content_help]"}} + } +} + ad_form -extend -name item_edit -form { {subtext:text,optional {label "[_ assessment.Subtext]"} {html {size 80 maxlength 500}} {value $subtext} {help_text "[_ assessment.item_Subtext_help]"}} {field_code:text,optional {label "[_ assessment.Field_Code]"} {html {size 80 maxlength 500}} {value $field_code} {help_text "[_ assessment.Field_Code_help]"}} Index: openacs-4/packages/assessment/www/admin/item-edit.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/item-edit.xql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/assessment/www/admin/item-edit.xql 29 Dec 2004 10:19:08 -0000 1.3 +++ openacs-4/packages/assessment/www/admin/item-edit.xql 7 Jan 2005 16:10:45 -0000 1.4 @@ -38,4 +38,17 @@+ - - select c.choice_id, r.title, c.correct_answer_p, c.feedback_text, - c.selected_p, c.percent_score - from as_item_choices c, cr_revisions r - where r.revision_id = c.choice_id - and c.mc_id = :mc_id - order by c.sort_order + update as_item_choices + set feedback_text = :feedback_text, + selected_p = :selected_p, + percent_score = :percent_score, + fixed_position = :fixed_position, + text_value = :answer_value + where choice_id = :choice_id + + update as_item_choices - set feedback_text = :feedback_text, - selected_p = :selected_p, - percent_score = :percent_score + set content_value = :content_rev_id where choice_id = :choice_id + ++ + update as_item_choices + set content_value = null + where choice_id = :choice_id + + ++ + Index: openacs-4/packages/assessment/www/admin/section-form.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/section-form.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/assessment/www/admin/section-form.tcl 29 Dec 2004 09:07:39 -0000 1.6 +++ openacs-4/packages/assessment/www/admin/section-form.tcl 7 Jan 2005 16:10:45 -0000 1.7 @@ -7,6 +7,7 @@ assessment_id:integer section_id:integer,optional after:integer,optional + {__new_p 0} } -properties { context_bar:onevalue page_title:onevalue @@ -22,12 +23,12 @@ ad_script_abort } -if {[info exists section_id]} { - set page_title [_ assessment.edit_section] - set _section_id $section_id -} else { +if {![info exists section_id] || $__new_p} { set page_title [_ assessment.add_new_section] set _section_id 0 +} else { + set page_title [_ assessment.edit_section] + set _section_id $section_id } set context_bar [ad_context_bar [list [export_vars -base one-a {assessment_id}] $assessment_data(title)] $page_title] @@ -53,7 +54,7 @@ ad_form -extend -name section_form -form { {title:text {label "[_ assessment.Title]"} {html {size 80 maxlength 1000}} {help_text "[_ assessment.section_Title_help]"}} - {description:text(textarea) {label "[_ assessment.Description]"} {html {rows 5 cols 80}} {help_text "[_ assessment.section_Description_help]"}} + {description:text(textarea),optional {label "[_ assessment.Description]"} {html {rows 5 cols 80}} {help_text "[_ assessment.section_Description_help]"}} } if {![empty_string_p [category_tree::get_mapped_trees $package_id]]} { @@ -64,6 +65,7 @@ {instructions:text(textarea),optional {label "[_ assessment.Instructions]"} {html {rows 5 cols 80}} {help_text "[_ assessment.section_Instructions_help]"}} {feedback_text:text(textarea),optional {label "[_ assessment.Feedback]"} {html {rows 5 cols 80}} {help_text "[_ assessment.section_Feedback_help]"}} {max_time_to_complete:integer,optional {label "[_ assessment.time_for_completion]"} {html {size 10 maxlength 10}} {help_text "[_ assessment.section_time_help]"}} + {num_items:integer,optional {label "[_ assessment.num_items]"} {html {size 5 maxlength 5}} {help_text "[_ assessment.num_items_help]"}} {points:integer,optional {label "[_ assessment.points_section]"} {html {size 10 maxlength 10}} {help_text "[_ assessment.points_item_help]"}} {display_type_id:text(select),optional {label "[_ assessment.Display_Type]"} {options $display_types} {help_text "[_ assessment.section_Display_Type_help]"}} } -new_request { @@ -73,10 +75,13 @@ set instructions "" set feedback_text "" set max_time_to_complete "" + set num_items "" set points "" set display_type_id "" } -edit_request { db_1row section_data {} +} -validate { + {name {[as::assessment::unique_name -name $name -new_p $__new_p]} "[_ assessment.name_used]"} } -on_submit { set category_ids [category::ad_form::get_categories -container_object_id $package_id] } -new_data { @@ -90,6 +95,7 @@ -instructions $instructions \ -feedback_text $feedback_text \ -max_time_to_complete $max_time_to_complete \ + -num_items $num_items \ -points $points \ -display_type_id $display_type_id] @@ -112,6 +118,7 @@ -instructions $instructions \ -feedback_text $feedback_text \ -max_time_to_complete $max_time_to_complete \ + -num_items $num_items \ -points $points \ -display_type_id $display_type_id] Index: openacs-4/packages/assessment/www/admin/section-form.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/section-form.xql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/assessment/www/admin/section-form.xql 10 Dec 2004 11:42:24 -0000 1.2 +++ openacs-4/packages/assessment/www/admin/section-form.xql 7 Jan 2005 16:10:45 -0000 1.3 @@ -18,7 +18,7 @@+ + select cr.title || ' (' || cr.content_length || ' bytes)' as content_name, + cr.revision_id as content_rev_id, cr.title as content_filename + from cr_revisions cr, as_item_rels r + where r.item_rev_id = :as_item_id + and r.target_rev_id = cr.revision_id + and r.rel_type = 'as_item_content_rel' + + +select ci.name, cr.title, cr.description, s.instructions, s.display_type_id, - s.feedback_text, s.max_time_to_complete, s.points + s.feedback_text, s.max_time_to_complete, s.points, s.num_items from as_sections s, cr_revisions cr, cr_items ci where cr.revision_id = s.section_id and ci.item_id = cr.item_id Index: openacs-4/packages/assessment/www/view/index.vuh =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/view/index.vuh,v diff -u -r1.1 -r1.2 --- openacs-4/packages/assessment/www/view/index.vuh 25 Oct 2004 16:05:11 -0000 1.1 +++ openacs-4/packages/assessment/www/view/index.vuh 7 Jan 2005 16:10:45 -0000 1.2 @@ -15,8 +15,7 @@ db_1row revision_info { *SQL* } set the_url $name -#set content_root [db_string get_folder_id { *SQL* }] -set content_root [db_string get_folder_id "select folder_id from cr_folders where package_id=:package_id"] +set content_root [as::assessment::folder_id -package_id $package_id] set template_root ""