aboutsummaryrefslogtreecommitdiff
path: root/GradeBook.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'GradeBook.tcl')
-rwxr-xr-xGradeBook.tcl71
1 files changed, 58 insertions, 13 deletions
diff --git a/GradeBook.tcl b/GradeBook.tcl
index 7df3c76..3ecfb42 100755
--- a/GradeBook.tcl
+++ b/GradeBook.tcl
@@ -81,6 +81,7 @@ proc CreateAccessRightsTable {db} {
db eval {INSERT INTO AccessRightsTable VALUES('renamecolumn', 1, 1, 0, 0)}
db eval {INSERT INTO AccessRightsTable VALUES('showcontrols', 1, 1, 0, 0)}
db eval {INSERT INTO AccessRightsTable VALUES('changegrades', 1, 1, 0, 0)}
+ db eval {INSERT INTO AccessRightsTable VALUES('updategrades', 1, 1, 0, 0)}
}
proc htmlDBout {db permission_list {sort_col {}}} {
@@ -155,17 +156,17 @@ proc htmlTop {permission_list} {
}
-proc htmlBottom {permission_list} {
+proc htmlFooter {permission_list} {
array set permission $permission_list
global VERSION
- puts "<div>"
+ puts "<div class=\"footer\">"
puts "GradeBook $VERSION code is written by Eugeniy Mikhailov"
puts "</div>"
}
proc LogOffOption {} {
global user password script_name
- puts "<div>"
+ puts "<div class=\"logoff\">"
puts "You are logged in as $user do you wish to "
puts "<a href=\"$script_name?action=logoff\">logoff</a>"
puts "</div>"
@@ -174,6 +175,7 @@ proc LogOffOption {} {
proc askToLogin {} {
global script_name
+ puts "<div class=\"login\">"
puts "Either you are here first time or you password and user name does not match. <br>"
puts "Please login <br>"
puts "<form name=\"input\" action=\"$script_name\" method=\"post\" />"
@@ -182,6 +184,7 @@ proc askToLogin {} {
puts {<input type="hidden" name="action" value="logon"/>}
puts {<input type="submit" value="Submit" />}
puts {</form>}
+ puts "</div>"
}
@@ -256,7 +259,10 @@ proc ChoseAction {action permission_list user} {
DeleteColumn $permission_list $user;
htmlDefaultView $permission_list $user
}
- changegrades { ChangeGrades $permission_list $user }
+ changegrades { ChangeGrades $permission_list $user }
+ updategrades { UpdateGrades $permission_list $user
+ htmlDefaultView $permission_list $user
+ }
renamecolumn { }
showcontrols { ShowControls $permission_list $user }
showgrades { htmlGradesTable db $permission_list $user }
@@ -266,6 +272,27 @@ proc ChoseAction {action permission_list user} {
}
}
+proc UpdateGrades { permission_list user } {
+ global script_name
+ set subaction [::ncgi::value subaction {}]
+ set columnname [::ncgi::value columnname {}]
+ set nv [::ncgi::nvlist]
+ array set colval $nv
+ if { $subaction eq "Submit" } {
+ set eval_str "SELECT UserName FROM GradesTable"
+ set err [catch {
+ db eval $eval_str v {
+ set sql_str [concat UPDATE GradesTable SET \"$columnname\"=\"$colval($v(UserName))\" where UserName=\"$v(UserName)\"]
+ db eval $sql_str
+ }
+
+ } errStat ]
+ if { $err } {
+ puts "the following error happen: $errStat"
+ dbg "the following error happen: $errStat" 3
+ }
+ }
+}
proc ChangeGrades { permission_list user } {
global script_name
@@ -273,9 +300,10 @@ proc ChangeGrades { permission_list user } {
if { $columnname != "" } {
# output only selected columns
set column_list {}
- lappend column_list FirstName LastName
+ lappend column_list FirstName LastName UserName
lappend column_list \"$columnname\"
set sql_column_list [join $column_list ","]
+ puts "<form name=\"input\" action=\"$script_name\" method=\"post\" />"
# output only selected columns
set eval_str "SELECT $sql_column_list FROM GradesTable ORDER BY LastName"
set show_header 1
@@ -294,7 +322,12 @@ proc ChangeGrades { permission_list user } {
}
foreach index $v(*) {
if { $index != "*" } {
- puts -nonewline "<td>$v($index)</td>"
+ if { $index eq $columnname } {
+ #column with grade
+ puts "<th><input type=\"text\" name=\"$v(UserName)\" value=\"$v($columnname)\" size=5></th>"
+ } else {
+ puts -nonewline "<td>$v($index)</td>"
+ }
}
}
puts "</tr>"
@@ -305,11 +338,10 @@ proc ChangeGrades { permission_list user } {
puts "the following error happen: $errStat"
dbg "the following error happen: $errStat" 3
}
- puts "<form name=\"input\" action=\"$script_name\" method=\"post\" />"
- #puts {<input type="hidden" name="action" value="updategrades"/>}
- puts {Column Name: <input type="text" name="columnname2add"><br>}
- puts {<input type="submit" name="action" value="Cancel" />}
- puts {<input type="submit" name="action" value="Submit" />}
+ puts {<input type="hidden" name="action" value="updategrades"/>}
+ puts [concat <input type="hidden" name="columnname" value="$columnname"/>]
+ puts {<input type="submit" name="subaction" value="Submit" />}
+ puts {<input type="submit" name="subaction" value="Cancel" />}
puts {</form>}
puts "<a href=\"$script_name\">Cancel changes</a>"
@@ -384,7 +416,7 @@ proc ShowControls { permission_list user } {
array set permission $permission_list
global script_name
dbg "outputing contol list"
- puts "<div>"
+ puts "<div class=\"controls\">"
set action_list [ list addcolumnrequest "Add Column" ]
set separator {}
foreach {act act_label} $action_list {
@@ -472,6 +504,16 @@ proc htmlDefaultView { permission_list user } {
ChoseAction showgrades $permission_list $user
}
+proc htmlHeader {} {
+puts {
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <meta http-equiv="Content-Type" content= "text/html; charset=us-ascii" />
+ <title>Grade Book</title>
+ <link rel="stylesheet" type="text/css" href="/~evmik/GradeBook.css" />
+</head>
+}
+}
##################### end of procs ####################################
@@ -489,12 +531,15 @@ dbg "===== Connection at $timestamp for user $user ====="
set permission_list [AccessGroupRights db $user $password]
::ncgi::header
+htmlHeader
+puts "<body>"
htmlTop $permission_list
ChoseAction $action $permission_list $user
#htmlDefaultView $permission_list $user
#htmlGradesTable db $permission_list $user
#htmlDBout db $sortCol
-htmlBottom $permission_list
+htmlFooter $permission_list
+puts "</body>"