aboutsummaryrefslogtreecommitdiff
path: root/GradeBook_lib.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'GradeBook_lib.tcl')
-rwxr-xr-xGradeBook_lib.tcl106
1 files changed, 105 insertions, 1 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl
index 4987b7d..21b89ea 100755
--- a/GradeBook_lib.tcl
+++ b/GradeBook_lib.tcl
@@ -32,6 +32,54 @@ proc AddUserNonWeb { first_name last_name user_name password_hash {group_name {g
}
}
+proc AddCourseInfoTableItem { item value } {
+ set eval_str [concat INSERT INTO CourseInfoTable (Item, Value) VALUES('$item', '$value') ]
+ set err [catch {db eval $eval_str } errStat]
+ if { $err } {
+ htmlErrorMsg $errStat
+ dbg "the following error happen: $errStat" 3
+ }
+}
+
+proc UpdateCourseInfoTableItem { item value } {
+ set sql_str [concat UPDATE CourseInfoTable SET \"Value\"=\'$value\' where Item=\"$item\"]
+ set err2 [catch {
+ db eval $sql_str
+ } errStat2 ]
+ if { $err2 } {
+ htmlErrorMsg $errStat2
+ dbg "the following error happen: $errStat2" 3
+ }
+}
+
+proc CreateCourseInfoTable {db} {
+ set err [catch {db eval {CREATE TABLE CourseInfoTable(Item text, Value text)} } errStat]
+ if { $err } {
+ htmlErrorMsg $errStat
+ dbg "the following error happen: $errStat" 1
+ }
+ AddCourseInfoTableItem course_title "Unset"
+ AddCourseInfoTableItem course_year "Unset"
+ AddCourseInfoTableItem course_semester "Unset"
+}
+
+proc SelectItemFromCourseInfoTable { item } {
+ set value {}
+ set eval_str "SELECT \"Value\" FROM CourseInfoTable where Item=\"$item\""
+ set err [catch {
+ db eval $eval_str v {
+ set value $v(Value)
+ }
+ } errStat ]
+ if { $err } {
+ htmlErrorMsg $errStat
+ dbg "the following error happen: $errStat" 3
+ }
+ return $value
+}
+
+
+
proc CreateGradesTable {db} {
set err [catch {db eval {CREATE TABLE GradesTable(FirstName text, LastName text, UserName text, PasswordHash text, GroupName text, UserHiddenColums text, UserHiddenGroups text, IdNum text, SectionNum text)} } errStat]
if { $err } {
@@ -84,6 +132,8 @@ proc CreateAccessRightsTable {db} {
AddAccessRightNonWeb userunhidecolumn 1 1 1 0
AddAccessRightNonWeb userhidegroup 1 0 0 0
AddAccessRightNonWeb userunhidegroup 1 0 0 0
+ AddAccessRightNonWeb editcourseinfo 1 0 0 0
+ AddAccessRightNonWeb updatecourseinfo 1 0 0 0
}
proc htmlErrorMsg { msg } {
@@ -223,6 +273,7 @@ proc htmlDBout {db permission_list user {sort_col {}}} {
}
proc htmlTop {permission_list} {
+ ClassInfoHtml
array set permission $permission_list
if { $permission(GroupName) == "guest" } {
askToLogin
@@ -256,12 +307,24 @@ proc SelectColValue4User { colname user } {
return $value
}
+proc ClassInfoHtml {} {
+ set CourseTitle [SelectItemFromCourseInfoTable course_title]
+ set CourseYear [SelectItemFromCourseInfoTable course_year]
+ set CourseSemester [SelectItemFromCourseInfoTable course_semester]
+ puts "<div class=\"header\">"
+ puts "<h1>Course grades for $CourseTitle</h1>"
+ puts "<h2>$CourseYear</h2>"
+ puts "<h2>$CourseSemester</h2>"
+ puts "</div>"
+}
+
proc Greetings {} {
global user password script_name
set FirstName UnknownFirstName
set LastName UnknownLastName
+
# get First and Last name info
set FirstName [SelectColValue4User FirstName $user]
set LastName [SelectColValue4User LastName $user]
@@ -368,6 +431,9 @@ proc ChoseAction {action permission_list user} {
userunhidegroup { UserUnHideGroup $permission_list $user
htmlDefaultView $permission_list $user }
showgrades { htmlGradesTable db $permission_list $user }
+ editcourseinfo { EditCourseInfo db $permission_list $user }
+ updatecourseinfo { UpdateCourseInfo db $permission_list $user
+ htmlDefaultView $permission_list $user }
defaultview { htmlDefaultView $permission_list $user }
default { htmlErrorMsg "requested action <b>$action</b> is granted but not implemented yet" }
}
@@ -377,6 +443,44 @@ proc ChoseAction {action permission_list user} {
}
}
+proc EditCourseInfo {db permission_list user } {
+ global script_name
+ set CourseTitle [SelectItemFromCourseInfoTable course_title]
+ set CourseYear [SelectItemFromCourseInfoTable course_year]
+ set CourseSemester [SelectItemFromCourseInfoTable course_semester]
+
+ puts "<div class=editcourseinfo>"
+ puts "<form name=\"input\" action=\"$script_name\" method=\"post\" />"
+ puts "Course title: <input type=\"text\" name=\"course_title\" value=\"$CourseTitle\"><br>"
+ puts "Course year: <input type=\"text\" name=\"course_year\" value=\"$CourseYear\"><br>"
+ puts "Course Semester: <input type=\"text\" name=\"course_semester\" value=\"$CourseSemester\"><br>"
+ puts {<input type="hidden" name="action" value="updatecourseinfo"/>}
+ puts {<input type="submit" name="subaction" value="Submit" />}
+ puts {<input type="submit" name="subaction" value="Cancel" />}
+ puts {</form>}
+ puts "</div>"
+}
+
+proc UpdateCourseInfo { db permission_list user } {
+ global script_name
+ set subaction [::ncgi::value subaction {}]
+ set CourseTitle [::ncgi::value course_title {}]
+ set CourseYear [::ncgi::value course_year {}]
+ set CourseSemester [::ncgi::value course_semester {}]
+ if { $subaction eq "Cancel" } {
+ return
+ }
+ if { $subaction eq "Submit" } {
+ UpdateCourseInfoTableItem course_title $CourseTitle
+ UpdateCourseInfoTableItem course_year $CourseYear
+ UpdateCourseInfoTableItem course_semester $CourseSemester
+ }
+ puts {<div class=infomsg>}
+ puts "Please click <span class=\"controls\"><a href=$script_name?action=defaultview>Refresh</a></span> to see ipdated course info."
+ puts {</div>}
+}
+
+
proc UserUnHideGroup { permission_list user } {
set groupname [::ncgi::value groupname {}]
set currently_hidden_groups [SelectColValue4User UserHiddenGroups $user]
@@ -710,7 +814,7 @@ proc ShowControls { permission_list user } {
global script_name
dbg "outputing contol list"
puts "<div class=\"controls\">"
- set action_list [ list defaultview "Refresh" addcolumnrequest "Add Column" logoff "Logoff" ]
+ set action_list [ list defaultview "Refresh" addcolumnrequest "Add Column" logoff "Logoff" editcourseinfo "Edit Course Info"]
set separator { }
foreach {act act_label} $action_list {
if { [isActionGranted $act $permission_list $user] } {