# $Header: /home/cvsroot/tcldb/ucodb/Tlib/PGgetSignOn,v 1.4 1998/03/22 21:43:58 de Exp $
# tcl procs saved on Sun Sep 03 16:18:49 PDT 1995

proc PGgetSignOn {} {
# profile on

  global uname
  global pw
  global env
  global matchInfo

  # get valid servers from interfaces file
   set pg_home [lsearch [array names env] POSTGRESDIR] 
 
   if {$pg_home == -1} {
       set pg_home ""
       set pg_home [exec grep postgres < /etc/passwd ]
       if {[string length $pg_home] > 0} {
           set pg_home [lindex [split $pg_home :] 5]
       } else {
           set pg_home ""
       }
   } else {
       set pg_home $env(POSTGRESDIR)
   }
 
  if {[info exists env(PGHOST)]} {
  lappend serverList $env(PGHOST)
  } else {
  puts stderr "oops you haven't set your PGHOST envar..."
  puts stderr "setting to localhost and crossing fingers.."
  set serverList localhost
  }

  wm geom     . 300x300+200+200

  frame .s -background bisque
  set font [getFont {} banner]
  message .s.m -justify center         -text "SQL Server Sign on" -aspect 2000         -font $font -background bisque
	
  frame .s.i -background bisque
  entry .s.i.uname -relief sunken  -width 19 -text uname -background ivory
#  label .s.i.id  -text "  User Id" -anchor e
  label .s.i.id  -text "  User Id" -background bisque
  frame .s.p -background bisque

#  set font [getFont {} secure]
#	the ashu quick patch for v4
  entry .s.p.pw  -relief sunken -width 19 -text pw -background ivory
  label .s.p.p   -text "  Database" -anchor e -background bisque

  frame .s.s -background bisque
  entry .s.s.ser -relief sunken -width 19 -background lemonchiffon
  menubutton .s.s.s -text " Server  " -anchor e -menu .s.s.s.m -relief raised -padx 0 -pady 0 -background lavender
  menu .s.s.s.m
  foreach s $serverList {
    .s.s.s.m add command -label $s                   -command ".s.s.ser delete 0 end; .s.s.ser insert 0 $s "
  }

  message .s.err -text "" -justify center -aspect 500 -background bisque

  frame .s.b -background bisque
  button .s.b.ok  -text "Sign on"       -command {PGtryConnect [.s.p.pw get] [.s.s.ser get]} -padx 0 -pady 0 -background lemonchiffon -activebackground lemonchiffon -activeforeground magenta2
  button .s.b.can -text "Cancel" -command "destroy ." -padx 0 -pady 0 -background white -activebackground red -activeforeground yellow -activebackground black

  pack .s -side top -fill both -expand true
  pack .s.m -side top -fill x -ipady 10
  pack .s.i -side top -ipady 10 -anchor e
  pack .s.i.uname -side right -expand true -ipadx 20
  pack .s.i.id -side left
  pack .s.p -side top -ipady 10 -anchor e
  pack .s.p.pw  -side right -expand true -ipadx 20
  pack .s.p.p  -side left

  pack .s.err -side top -fill x -expand true
  pack .s.b -side bottom -fill x 
  pack .s.b.ok -side left -fill x -expand true 
  pack .s.b.can -side left -fill x -expand true

  pack .s.s -side bottom -ipady 10 -anchor e
  pack .s.s.ser -side right -expand true -ipadx 20
  pack .s.s.s  -side left

#  no longer needed, tied to text var now
#  .s.i.uname insert 0 $uname

  if {[lsearch [array names env] PGHOST] >= 0} {
    .s.s.ser insert 0 $env(PGHOST)
  } else {
    .s.s.ser insert 0 localhost
  }

  bind .s.i.uname <KeyPress-Return> "focus .s.p.pw"
  bind .s.p.pw  <KeyPress-Return> ".s.b.ok invoke"
  bind .s.s.ser <KeyPress-Return> ".s.b.ok invoke"

  if {$uname != ""} {
  focus .s.p.pw
  } else {
  focus .s.i.uname
  }

}

