diff options
-rwxr-xr-x | db_procs.tcl | 102 |
1 files changed, 95 insertions, 7 deletions
diff --git a/db_procs.tcl b/db_procs.tcl index 5ad05f2..53f6ac5 100755 --- a/db_procs.tcl +++ b/db_procs.tcl @@ -1,6 +1,6 @@ #!/bin/sh -# FILE: "/home/evmik/src/my_src/GradeBook/db_procs.tcl" -# LAST MODIFICATION: "Mon, 13 Dec 2010 17:27:51 -0500 (evmik)" +# FILE: "/mnt/light_huge_archive/home/evmik/src/my_src/GradeBook/db_procs.tcl" +# LAST MODIFICATION: "Tue, 14 Dec 2010 01:15:22 -0500 (evmik)" # (C) 2010 by Eugeniy Mikhailov, <evgmik@gmail.com> # $Id:$ # vim:set ft=tcl: \ @@ -9,18 +9,23 @@ exec tclsh "$0" "$@" #load libtclsqlite3.so.0 Sqlite3 package require sqlite3 package require ncgi -::ncgi::header - ::ncgi::parse -set script_name $env(SCRIPT_NAME) + +set user [::ncgi::cookie user] +set password [::ncgi::cookie password] +set action [::ncgi::value action none] + +if { [catch {set script_name $env(SCRIPT_NAME)} errStat] } { set script_name unknown} #set val [::ncgi::value fd] set sortCol [::ncgi::value sortCol LastName] proc dbg {msg {level 1}} { if { $level <=2 } { - puts $msg + set fid [open log a+] + puts $fid $msg + close $fid } } @@ -91,6 +96,89 @@ proc htmlDBout {db {sort_col {}}} { puts "</table>" } -#createDB db +proc htmlTop {} { + global user password + if { $user == "guest" && $password == "guest" } { + askToLogin + } else { + LogOffOption + } + +} + +proc LogOffOption {} { + global user password script_name + puts "<div>" + puts "You are logged in as $user do you wish to " + puts "<a href=\"$script_name?action=logoff\">logoff</a>" + puts "</div>" + +} + +proc askToLogin {} { + global script_name + puts "Please login <br>" + puts "<form name=\"input\" action=\"$script_name\" method=\"post\" />" + puts {Login: <input type="text" name="user"><br>} + puts {Password: <input type="password" name="password"><br>} + puts {<input type="hidden" name="action" value="logon"/>} + puts {<input type="submit" value="Submit" />} + puts {</form>} +} + + + + +proc CheckAccessRights { user password} {} +proc IsUserknown {} {return 1} + +proc SetLoginInfo {} { + global user password + set isAccessGranted [IsUserknown] + if { $isAccessGranted } { + dbg "access granted to user $user" + } + + set access_rights [CheckAccessRights $user $password] + +} + +proc LogMeOn {} { + global user password + set user [::ncgi::value user guest] + set password [::ncgi::value password guest] + dbg "Logging in and setting cookies" + ::ncgi::setCookie -name user -value $user + ::ncgi::setCookie -name password -value $password +} + +proc LogMeOff {} { + dbg "Logging off" + global user password + set user guest + set password guest + ::ncgi::setCookie -name user -value $user + ::ncgi::setCookie -name password -value $password + +} + +proc ChoseAction {action} { + dbg "requeste action: $action" 3 + switch $action { + logon { LogMeOn } + logoff { LogMeOff } + default { } + } +} + +##################### end of procs #################################### +dbg [::ncgi::names] 4 +dbg "sdaf dsaf $action " +ChoseAction $action +::ncgi::header +htmlTop htmlDBout db $sortCol + + + |