From 574401ff1c22353e55a58681334f3e8ce257dfce Mon Sep 17 00:00:00 2001 From: Eugeniy Mikhailov Date: Fri, 15 Apr 2011 16:01:31 -0400 Subject: added code to edit categories weight Ignore-this: 6a18fd7ba0b7442ee9b86a98f02813be darcs-hash:20110415200131-067c0-d1fb4e0d5dbb424ded0807841a8b5d4402f8a1c6.gz --- GradeBook_lib.tcl | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 2 deletions(-) (limited to 'GradeBook_lib.tcl') diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl index e31dd6c..ddc3476 100755 --- a/GradeBook_lib.tcl +++ b/GradeBook_lib.tcl @@ -6,7 +6,7 @@ exec tclsh "$0" "$@" # require Tcl version of at least 8.5 since I use 'ni' and 'in' in expressions for lists package require Tcl 8.5 # internal version of this code -set VERSION 1.4.5 +set VERSION 1.5.0 # Grades category and their html names set grades_category [list \ @@ -361,7 +361,6 @@ proc ModifyWeightForGradesCategory {db category weight} { AddGradesCategory db $category } set eval_str [concat UPDATE GradesCategoryTable SET \"CategoryWeight\"='$weight' WHERE \"CategoryName\"=\'$category\'] - puts $eval_str set err [catch {db eval $eval_str } errStat] if { $err } { htmlErrorMsg $errStat @@ -397,6 +396,83 @@ proc CreateGradesCategoryTable {db} { } } +proc UpdateGradesCategores { db permission_list user } { + global script_name + set subaction [::ncgi::value subaction {}] + set nv [::ncgi::nvlist] + array set colval $nv + if { $subaction eq "Cancel" } { + return + } + if { $subaction eq "Submit" } { + set eval_str "SELECT CategoryName FROM GradesCategoryTable" + set err [catch { + db eval $eval_str v { + if { [info exist colval($v(CategoryName))] } { + ModifyWeightForGradesCategory db $v(CategoryName) $colval($v(CategoryName)) + } + } + } errStat ] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 3 + } + } + + calculteWeightedTotals +} + +proc EditGradesCategories { db permission_list user } { + global script_name + lappend column_list CategoryName CategoryWeight + set sql_column_list [join $column_list ","] + puts {
} + puts {
} + puts "
" + # output only selected columns + set eval_str "SELECT $sql_column_list FROM GradesCategoryTable" + set show_header 1 + set err [catch { + db eval $eval_str v { + if { $show_header } { + set show_header 0 + puts {} + puts "" + foreach col $v(*) { + puts -nonewline "" + } + puts "" + } else { + puts "" + } + foreach index $v(*) { + if { $index != "*" } { + if { $index eq "CategoryWeight" } { + puts "" + } else { + puts -nonewline "" + } + } + } + puts "" + } + } errStat ] + puts "
$col
$v($index)
" + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 3 + } + puts {} + puts {} + puts {} + puts {
} + puts {
} + puts {
} + #puts "Cancel changes" + +} + + proc CreateGradesTable {db} { # construct sql string for table creation set sql_str {CREATE TABLE GradesTable(} @@ -454,6 +530,8 @@ proc CreateAccessRightsTable {db} { AddAccessRightNonWeb showcontrols 1 1 1 1 0 AddAccessRightNonWeb changegrades 1 1 0 0 0 AddAccessRightNonWeb updategrades 1 1 0 0 0 + AddAccessRightNonWeb edit_grades_categories 1 0 0 0 0 + AddAccessRightNonWeb update_grades_categories 1 0 0 0 0 AddAccessRightNonWeb changecolumn 1 1 0 0 0 AddAccessRightNonWeb updatecolumn 1 1 0 0 0 AddAccessRightNonWeb logoff 1 1 1 1 0 @@ -921,6 +999,9 @@ proc ChoseAction {action permission_list user} { userunhidegradecategory { UserUnHideGradeCategory $permission_list $user htmlDefaultView $permission_list $user } showgrades { htmlGradesTable db $permission_list $user } + edit_grades_categories { EditGradesCategories db $permission_list $user } + update_grades_categories { UpdateGradesCategores db $permission_list $user + htmlDefaultView $permission_list $user } editcourseinfo { EditCourseInfo db $permission_list $user } updatecourseinfo { UpdateCourseInfo db $permission_list $user htmlDefaultView $permission_list $user } @@ -1479,6 +1560,7 @@ proc ShowControls { permission_list user } { editcourseinfo "Edit Course Info"\ editnewuserinfo "Add new user"\ choosenewpassword "Choose new password"\ + edit_grades_categories "Edit Grades Categories and Weights"\ logoff "Logoff"\ ] set separator { } -- cgit v1.2.3