blob: 9193cdf0e106f788d3944aaf6bd47739308bf41e (
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
|
#!/bin/sh
# (C) 2010 by Eugeniy Mikhailov, <evgmik@gmail.com>
# vim:set ft=tcl: \
exec tclsh "$0" "$@"
set err [catch {
# require Tcl version of at least 8.5 since I use 'ni' and 'in' in expressions for lists
package require ncgi
package require Tcl 8.5
package require sqlite3
package require md5
} errStat ]
if { $err } {
::ncgi::header
puts "the following error happen: $errStat"
exit
}
###################### Main script begins #################################
set err [catch {
set execution_start_time [clock microseconds]
source ./GradeBook_lib.tcl
::ncgi::parse
# defaults
set sortCol LastName
set user guest
set password guest
set action defaultview
# defaults end
# read cookies
set user_requested [::ncgi::cookie user]
set sortCol [::ncgi::cookie sortCol]
set password [::ncgi::cookie password]
set action [::ncgi::value action defaultview]
# end of read cookies
# get hostname
if { [catch {set host_name $env(SERVER_NAME)} errStat] } { set request_uri unknown}
# script uri
if { [catch {set script_name $env(SCRIPT_NAME)} errStat] } { set script_name unknown}
set script_root_name $script_name
# figure out course db filename
if { [catch {set request_uri $env(REQUEST_URI)} errStat] } { set request_uri unknown}
regsub -all $script_name $request_uri "" coursedbfname
regsub -all {\?.*$} $coursedbfname "" coursedbfname
regsub -all {^/} $coursedbfname "" coursedbfname
set script_name "$script_name/$coursedbfname"
set timestamp [clock format [clock seconds] -format "%Y-%m-%dT%H:%M:%S"]
#CreateGradesTable db
#CreateAccessRightsTable db
dbg [::ncgi::names] msg_level_info
# logon and logoff actions are granted to everyone
if { $action == "logon" } { set action [ LogMeOn ] }
if { $action == "logoff" } { LogMeOff; set action defaultview }
dbg "===== Connection at $timestamp for user $user_requested =====" msg_level_log
::ncgi::header
set user [ Authenticate_User $user_requested $password ]
dbg "Requested user $user_requested logged in as $user" msg_level_info
set dbfile "$GradebookServerConfig(grades_db_dir)/$coursedbfname"
if { [file exists $dbfile] && ("$coursedbfname" ne "") } {
htmlHeader
puts "<body>"
sqlite3 db $dbfile
set permission_list [ AccessGroupRights db $user ]
htmlTop $permission_list
ChoseAction $action $permission_list $user
db close
} else {
htmlHeaderDBSelector
set permission_list [list GroupName guest]
puts "<body>"
if { "$coursedbfname" ne "" } {
htmlErrorMsg "No requested database {$coursedbfname}. Please, check your url"
dbg "Attemt to access non existing database: {$dbfile}" msg_level_info
}
html_Show_Classes_List $permission_list $user
}
dbg $permission_list msg_level_info
htmlFooter $permission_list
puts "</body>"
###################### Main script ends #################################
} errStat ]
if { $err } {
dbg "Error: $errStat" msg_level_critical
htmlErrorMsg "Something went wrong, please, ask admin to have a look at logs"
}
# vim: ts=2 sw=2 foldmethod=indent:
|