summaryrefslogtreecommitdiff
path: root/CreateCourseGradeBook.tcl
blob: 491e2d099f459f4dc42164afac4410625e7aa4c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/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

	#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: