diff options
-rwxr-xr-x | CreateCourseGradeBook.tcl | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/CreateCourseGradeBook.tcl b/CreateCourseGradeBook.tcl new file mode 100755 index 0000000..c0ddf2c --- /dev/null +++ b/CreateCourseGradeBook.tcl @@ -0,0 +1,128 @@ +#!/bin/sh +# (C) 2011 by Eugeniy Mikhailov, <evgmik@gmail.com> +# vim:set ft=tcl: \ +exec tclsh "$0" "$@" + +package require sqlite3 +package require md5 + +set class [lindex $argv 0] +if { $class eq "" } { + set class dummy_class +} + +set dbfile $class + +sqlite3 db $dbfile + +proc dbg {msg {level 1}} { + if { $level <=2 } { + set fid [open log a+] + puts $fid $msg + close $fid + } +} + +proc htmlErrorMsg { msg } { + puts "<div class=\"errormsg\">error: $msg</div>" +} + +proc AddUserNonWeb { first_name last_name user_name password_hash {group_name {guest}} {id_number {}} {section_num {} } } { + set eval_str [concat INSERT INTO GradesTable (FirstName, LastName, UserName, PasswordHash, GroupName, IdNum, SectionNum) VALUES('$first_name', '$last_name', '$user_name', '$password_hash', '$group_name', '$id_number', '$section_num')] + set err [catch {db eval $eval_str } errStat] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 3 + } +} + + +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 } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 1 + } + + # add special users aka special info rows + AddUserNonWeb {} {} _Col_Category_ {} inforow + AddUserNonWeb {} {} _Max_Points_ {} inforow + + # dummy users + AddUserNonWeb Ta "Taevich, I" ta [::md5::md5 -hex qwerty] ta + AddUserNonWeb Dan "Dandanovich" dan [::md5::md5 -hex qwerty] student + AddUserNonWeb Ale "Alevna" ale [::md5::md5 -hex qwerty] student + AddUserNonWeb Jon "Jonovich" jon [::md5::md5 -hex qwerty] student + AddUserNonWeb Ins "Instruch I" instructor [::md5::md5 -hex qwerty] instructor + # reasonable defaults for hidden columns + set instructor_hidden_columns [list UserHiddenColums PasswordHash UserHiddenGroups IdNum] + UpdateColValue4GroupNameNonWeb UserHiddenColums instructor $instructor_hidden_columns +} + +proc AddAccessRightNonWeb { action instructor_right ta_right student_right guest_right } { + set eval_str [concat INSERT INTO AccessRightsTable (actionname, instructor, ta, student, guest) VALUES('$action', '$instructor_right', '$ta_right', '$student_right', '$guest_right')] + set err [catch {db eval $eval_str } errStat] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 3 + } +} + +proc CreateAccessRightsTable {db} { + set err [catch {db eval {CREATE TABLE AccessRightsTable(actionname text, instructor integer, ta integer, student integer, guest integer)} } errStat] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 1 + } + # guest should have no rights make sure that 0 is evereywhere except logon + # actionname instructor ta student guest + AddAccessRightNonWeb logon 1 1 1 1 + AddAccessRightNonWeb showgrades 1 1 1 0 + AddAccessRightNonWeb sort 1 1 0 0 + AddAccessRightNonWeb addcolumnrequest 1 1 0 0 + AddAccessRightNonWeb addcolumn 1 1 0 0 + AddAccessRightNonWeb deletecolumn 1 1 0 0 + AddAccessRightNonWeb showcontrols 1 1 1 0 + AddAccessRightNonWeb changegrades 1 1 0 0 + AddAccessRightNonWeb updategrades 1 1 0 0 + AddAccessRightNonWeb changecolumn 1 1 0 0 + AddAccessRightNonWeb updatecolumn 1 1 0 0 + AddAccessRightNonWeb logoff 1 1 1 0 + AddAccessRightNonWeb changefirstname 1 0 0 0 + AddAccessRightNonWeb changelastname 1 0 0 0 + AddAccessRightNonWeb changeusername 1 0 0 0 + AddAccessRightNonWeb userhidecolumn 1 1 1 0 + AddAccessRightNonWeb userunhidecolumn 1 1 1 0 + AddAccessRightNonWeb userhidegroup 1 0 0 0 + AddAccessRightNonWeb userunhidegroup 1 0 0 0 +} + +proc UpdateColValue4UserNameNonWeb { columnname username val } { + set sql_str [concat UPDATE GradesTable SET \"$columnname\"=\'$val\' where UserName=\"$username\"] + set err2 [catch { + db eval $sql_str + } errStat2 ] + if { $err2 } { + htmlErrorMsg $errStat2 + dbg "the following error happen: $errStat2" 3 + } +} + +proc UpdateColValue4GroupNameNonWeb { columnname groupname val } { + set sql_str [concat UPDATE GradesTable SET \"$columnname\"=\'$val\' where GroupName=\"$groupname\"] + set err2 [catch { + db eval $sql_str + } errStat2 ] + if { $err2 } { + htmlErrorMsg $errStat2 + dbg "the following error happen: $errStat2" 3 + } +} + + +CreateGradesTable db +CreateAccessRightsTable db + + + +# vim: ts=2 sw=2 foldmethod=indent: |