Index: openacs-4/packages/evaluation/www/admin/evaluations/evaluate-students-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/evaluation/www/admin/evaluations/evaluate-students-2.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/evaluation/www/admin/evaluations/evaluate-students-2.tcl 28 Apr 2004 11:06:41 -0000 1.1 +++ openacs-4/packages/evaluation/www/admin/evaluations/evaluate-students-2.tcl 12 May 2004 02:07:45 -0000 1.2 @@ -5,9 +5,9 @@ @author jopez@galileo.edu @creation-date Mar 2004 + @cvs_id $Id$ } { task_id:integer,notnull - grade_id:integer,notnull,optional max_grade:integer,notnull,optional item_ids:array,integer,optional item_to_edit_ids:array,optional @@ -24,8 +24,29 @@ comments_na:array,optional show_student_na:array,optional - {return_url "student-list?[export_vars -url { task_id }]"} + grades_gs:array,optional + comments_gs:array,optional + show_student_gs:array,optional + new_p_gs:array,optional + grades_sheet_item_id:integer,optional + upload_file:optional + {tmp_filename:optional ""} + } -validate { + valid_grades_gs { + set counter 0 + foreach party_id [array names grades_gs] { + if { [info exists grades_gs($party_id)] && ![empty_string_p $grades_gs($party_id)] } { + incr counter + if { ![ad_var_type_check_number_p $grades_gs($party_id)] } { + ad_complain "The grade most be a valid number ($grades_gs($party_id))" + } + } + } + if { !$counter && ([array size show_student_gs] > 0) } { + ad_complain "There must be at least one grade to work with" + } + } valid_grades_wa { set counter 0 foreach party_id [array names grades_wa] { @@ -69,6 +90,14 @@ } } valid_data { + foreach party_id [array names comments_gs] { + if { [info exists comments_gs($party_id)] && ![info exists grades_gs($party_id)] } { + ad_complain "There is a comment for a grade not realized ($comments_gs($party_id))" + } + if { [info exists comments_gs($party_id)] && ([string length $comments_gs($party_id)] > 400) } { + ad_complain "There is a comment larger than we can handle. ($comments_gs($party_id))" + } + } foreach party_id [array names comments_wa] { if { [info exists comments_wa($party_id)] && ![info exists grades_wa($party_id)] } { ad_complain "There is a comment for a grade not realized ($comments_wa($party_id))" @@ -96,6 +125,53 @@ } } +if { ![empty_string_p $tmp_filename] } { + + set tmp_filename "${tmp_filename}_grades_sheet" + + db_transaction { + + set title [template::util::file::get_property filename $upload_file] + set mime_type [cr_filename_to_mime_type -create $title] + + set revision_id [evaluation::new_grades_sheet -new_item_p 1 -item_id $grades_sheet_item_id -content_type evaluation_grades_sheets \ + -content_table evaluation_grades_sheets -content_id grades_sheet_id -storage_type lob -task_id $task_id \ + -title $title -mime_type $mime_type] + + evaluation::set_live -revision_id $revision_id + + # create the new item + db_dml lob_content " update cr_revisions + set lob = [set __lob_id [db_string get_lob_id "select empty_lob()"]] + where revision_id = :revision_id + " -blob_files [list $tmp_filename] + + set content_length [file size $tmp_filename] + # Unfortunately, we can only calculate the file size after the lob is uploaded + db_dml lob_size { update cr_revisions + set content_length = :content_length + where revision_id = :revision_id + } + + foreach party_id [array names grades_gs] { + if { ![info exists comments_gs($party_id)] } { + set comments_gs($party_id) "" + } else { + set comments_gs($party_id) [DoubleApos $comments_gs($party_id)] + } + + if { [info exists grades_gs($party_id)] && ![empty_string_p $grades_gs($party_id)] } { + set grades_gs($party_id) [expr ($grades_gs($party_id)*100)/$max_grade.0] + set revision_id [evaluation::new_evaluation -new_item_p $new_p_gs($party_id) -item_id $item_ids($party_id) -content_type evaluation_student_evals \ + -content_table evaluation_student_evals -content_id evaluation_id -description $comments_gs($party_id) \ + -show_student_p $show_student_gs($party_id) -grade $grades_gs($party_id) -task_id $task_id -party_id $party_id] + + evaluation::set_live -revision_id $revision_id + } + } + } +} + db_transaction { foreach party_id [array names grades_wa] { if { ![info exists comments_wa($party_id)] } { @@ -146,5 +222,5 @@ } } -ad_returnredirect "$return_url" +ad_returnredirect "student-list?[export_vars { task_id } ]"