diff options
author | Eugeniy Mikhailov <evgmik@gmail.com> | 2011-03-06 15:07:40 -0500 |
---|---|---|
committer | Eugeniy Mikhailov <evgmik@gmail.com> | 2011-03-06 15:07:40 -0500 |
commit | 223cc32442432c125e71c6204492f0bf0755cb8d (patch) | |
tree | ce8d34eb7d0a905fa37599ef873abb381a0e1c1b /GradeBook_lib.tcl | |
parent | 254713e76e2c9eb6291cbed607d11c6b49863438 (diff) | |
download | GradeBook-223cc32442432c125e71c6204492f0bf0755cb8d.tar.gz GradeBook-223cc32442432c125e71c6204492f0bf0755cb8d.zip |
grades category match to its htmls name automatically
Ignore-this: 44290dbfe92d2d67b1bc4379a1d1c873
darcs-hash:20110306200740-067c0-2b07184729d67b679103b9a6db3f21f2f60398ff.gz
Diffstat (limited to 'GradeBook_lib.tcl')
-rwxr-xr-x | GradeBook_lib.tcl | 68 |
1 files changed, 42 insertions, 26 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl index d04d00e..2031dd6 100755 --- a/GradeBook_lib.tcl +++ b/GradeBook_lib.tcl @@ -6,7 +6,31 @@ 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.1.2 +set VERSION 1.1.3 + +# Grades category and their html names +set grades_category [list \ + "unset"\ + Quiz\ + HomeWork\ + LabReport\ + MidTerm\ + FinalExam\ + ] + +proc grade_Category2html_name { category } { + switch $category { + "unset" {set html_name --Select--} + Quiz {set html_name Quiz} + HomeWork {set html_name HomeWork} + LabReport {set html_name LabReport} + MidTerm {set html_name MidTerm} + FinalExam {set html_name FinalExam} + default {set html_name unknown} + } + return $html_name +} + # ########################## procs begin ################################# proc dbg {msg {level 1}} { @@ -167,6 +191,7 @@ proc htmlReplaceEmptyString { string } { proc htmlDBout {db permission_list user {sort_col {}}} { array set permission $permission_list global script_name + global grades_category set defSortCol LastName if { $sort_col == {} } { @@ -228,16 +253,13 @@ proc htmlDBout {db permission_list user {sort_col {}}} { default { dbg "Default must not be allowed to set table view port. Aborting. This line is never executed." 0; exit } } if { $sql_column_str ne "" } { - switch [SelectColValue4User $sort_col _Col_Category_] { - Quiz { set ordered_by_str [concat CAST(\"$sort_col\" AS REAL)] } - LabReport { set ordered_by_str [concat CAST(\"$sort_col\" AS REAL)] } - HomeWork { set ordered_by_str [concat CAST(\"$sort_col\" AS REAL)] } - MidTerm { set ordered_by_str [concat CAST(\"$sort_col\" AS REAL)] } - FinalExam { set ordered_by_str [concat CAST(\"$sort_col\" AS REAL)] } - FinalExam { set ordered_by_str [concat CAST(\"$sort_col\" AS REAL)] } - default { set ordered_by_str \"$sort_col\" } + # assign type cast for different sort_col + if { [SelectColValue4User $sort_col _Col_Category_] in $grades_category } { + set ordered_by_str [concat CAST(\"$sort_col\" AS REAL)] + } else { + set ordered_by_str \"$sort_col\" } - # get all allowed columns and rows + r get all allowed columns and rows set eval_str [concat SELECT $sql_column_str FROM GradesTable $where_statement ORDER BY $ordered_by_str] set err [catch { db eval $eval_str v { @@ -765,6 +787,7 @@ proc ChangeColumn { permission_list user } { set category "unset" set category [SelectColValue4User $columnname _Col_Category_] set maxpoints [SelectColValue4User $columnname _Max_Points_] + global grades_category puts {<div class="add_new_column">} puts "<form name=\"input\" method=\"post\" />" @@ -774,16 +797,8 @@ proc ChangeColumn { permission_list user } { set out_str {} append out_str {Category: <select name="category" value="} $category {">} puts $out_str - # opt list has option name and corresponding text pairs - set opt_list [list \ - unset --Select--\ - Quiz Quiz\ - HomeWork HomeWork\ - LabReport LabReport\ - MidTerm MidTerm\ - FinalExam FinalExam\ - ] - foreach {name txt} $opt_list { + foreach {name} $grades_category { + set txt [grade_Category2html_name $name] set out_str {} if { $name eq $category } { append out_str {<option value="} $name {" selected>} $txt {</option>} @@ -1042,16 +1057,17 @@ proc AddColumn { permission_list user } { proc AddColumnRequest { permission_list user } { global script_name + global grades_category puts {<div class="add_new_column">} puts "<form name=\"input\" method=\"post\" />" puts {Column Name: <input type="text" name="columnname2add"><br>} puts {Category: <select name="column_category">} - puts {<option value="unset">--Select--</option>} - puts {<option value="Quiz">Quiz</option>} - puts {<option value="HomeWork">HomeWork</option>} - puts {<option value="LabReport">LabReport</option>} - puts {<option value="MidTerm">MidTerm</option>} - puts {<option value="FinalExam">FinalExam</option>} + foreach {name} $grades_category { + set txt [grade_Category2html_name $name] + set out_str {} + append out_str {<option value="} $name {">} $txt {</option>} + puts $out_str + } puts {</select> <br>} puts {Max Point Possible:<input type="text" name="maxpointpossible"><br>} puts {<input type="hidden" name="action" value="addcolumn"/>} |