aboutsummaryrefslogtreecommitdiff
path: root/GradeBook.tcl
diff options
context:
space:
mode:
authorEugeniy Mikhailov <evgmik@gmail.com>2010-12-15 00:33:06 -0500
committerEugeniy Mikhailov <evgmik@gmail.com>2010-12-15 00:33:06 -0500
commit6a84f46222a534390e885c06fd19be889e6b74af (patch)
treeef1011f360a94fc2f6ed56e144168ba3990368f4 /GradeBook.tcl
parent3cefda164ff6e271573831fa2fea0c92b1f37bcd (diff)
downloadGradeBook-6a84f46222a534390e885c06fd19be889e6b74af.tar.gz
GradeBook-6a84f46222a534390e885c06fd19be889e6b74af.zip
added permission use draft
darcs-hash:20101215053306-067c0-bdea0ff876fd52662905acb761e321cefaff218e.gz
Diffstat (limited to 'GradeBook.tcl')
-rwxr-xr-xGradeBook.tcl75
1 files changed, 51 insertions, 24 deletions
diff --git a/GradeBook.tcl b/GradeBook.tcl
index 7b7adf4..f26f2f2 100755
--- a/GradeBook.tcl
+++ b/GradeBook.tcl
@@ -1,6 +1,6 @@
#!/bin/sh
-# FILE: "/home/evmik/src/my_src/GradeBook/GradeBook.tcl"
-# LAST MODIFICATION: "Tue, 14 Dec 2010 17:36:43 -0500 (evmik)"
+# FILE: "/mnt/light_huge_archive/home/evmik/src/my_src/GradeBook/GradeBook.tcl"
+# LAST MODIFICATION: "Wed, 15 Dec 2010 00:33:04 -0500 (evmik)"
# (C) 2010 by Eugeniy Mikhailov, <evgmik@gmail.com>
# $Id:$
# vim:set ft=tcl: \
@@ -42,8 +42,8 @@ set dbfile "./testdb"
sqlite3 db $dbfile
-proc createDB {db} {
- db eval {CREATE TABLE GradesTable(FirstName text, LastName text, UserName text, HW01 float)}
+proc CreateGradesTable {db} {
+ db eval {CREATE TABLE GradesTable(FirstName text, LastName text, UserName text, HW01 real)}
db eval {INSERT INTO GradesTable VALUES('John','Lname1', 'jhn', 7)}
db eval {INSERT INTO GradesTable VALUES('Ale','Lname2', 'ale', 5)}
@@ -51,6 +51,14 @@ proc createDB {db} {
#db1 eval {ALTER TABLE GradesTable ADD c int }
}
+proc CreateAccessRightsTable {db} {
+ db eval {CREATE TABLE AccessRightsTable(GroupName text, sort integer, addcolumn integer, deletecolumn integer)}
+ db eval {INSERT INTO AccessRightsTable VALUES('instructor', 1, 1, 1)}
+ db eval {INSERT INTO AccessRightsTable VALUES('ta', 1, 1, 1)}
+ db eval {INSERT INTO AccessRightsTable VALUES('student', 1, 0, 0)}
+ # guest should have no rights make sure that 0 is evereywhere
+ db eval {INSERT INTO AccessRightsTable VALUES('guest', 0, 0, 0)}
+}
proc htmlDBout {db {sort_col {}}} {
#set x [db eval {SELECT * FROM GradesTable ORDER BY a}]
@@ -103,9 +111,9 @@ proc htmlDBout {db {sort_col {}}} {
puts "</table>"
}
-proc htmlTop {} {
- global user password
- if { $user == "guest" && $password == "guest" } {
+proc htmlTop {permission_list} {
+ array set permission $permission_list
+ if { $permission(GroupName) == "guest" } {
askToLogin
} else {
LogOffOption
@@ -139,16 +147,16 @@ proc askToLogin {} {
proc CheckAccessRights { user password} {}
proc IsUserknown {} {return 1}
-proc SetLoginInfo {} {
- global user password
- set isAccessGranted [IsUserknown]
- if { $isAccessGranted } {
- dbg "access granted to user $user"
- }
+#proc SetLoginInfo {} {
+ #global user password
+ #set isAccessGranted [IsUserknown]
+ #if { $isAccessGranted } {
+ #dbg "access granted to user $user"
+ #}
- set access_rights [CheckAccessRights $user $password]
+ #set access_rights [CheckAccessRights $user $password]
-}
+#}
proc LogMeOn {} {
global user password
@@ -175,24 +183,43 @@ proc SetSortColumn {} {
::ncgi::setCookie -name sortCol -value $sortCol
}
-proc ChoseAction {action} {
- dbg "requeste action: $action" 3
+proc ChoseAction {action permission_list} {
+ array set permission $permission_list
+ dbg "requested action: $action" 3
switch $action {
- logon { LogMeOn }
- logoff { LogMeOff }
- sort { SetSortColumn }
+ sort {
+ if { $permission(logoff) } { LogMeOff }
+ }
default { }
}
}
+proc AccessGroupRights {db user password } {
+ if { $user == "guest"} {
+ set group guest
+ } else {
+ set group instructor
+ }
+ set eval_str [list SELECT * FROM AccessRightsTable WHERE GroupName == '$group']
+ db eval $eval_str permissions {}
+ array unset permissions {\*}
+ dbg "permissions are: [array get permissions]"
+ return [array get permissions]
+}
+
##################### end of procs ####################################
-#createDB db
+#CreateGradesTable db
+#CreateAccessRightsTable db
dbg [::ncgi::names] 4
-dbg "sdaf dsaf $action "
-ChoseAction $action
+# logon and logoff actions are granted to everyone
+if { $action == "logon" } { LogMeOn }
+if { $action == "logoff" } { LogMeOff }
+
+set permissions [AccessGroupRights db $user $password]
+ChoseAction $action $permissions
::ncgi::header
-htmlTop
+htmlTop $permissions
htmlDBout db $sortCol