# $Header: /home/cvsroot/tcldb/ucodb/Tlib/SYBgetSignOn,v 1.5 1999/10/13 23:22:17 de Exp $
# tcl procs saved on Sun Sep 03 16:18:49 PDT 1995

proc SYBgetSignOn {} {
# profile on

  global uname
  global pw
  global env
  global matchInfo

  # get valid servers from interfaces file
   set syb_home [lsearch [array names env] SYBASE] 
 
   if {$syb_home == -1} {
       set syb_home ""
       catch {set syb_home [exec ypcat passwd | egrep  ^sybase: ]}
       if {[string length $syb_home] > 0} {
       set syb_home [lindex [split $syb_home :] 5]
       } else {
       set syb_home [exec egrep ^sybase: < /etc/passwd ]
       if {[string length $syb_home] > 0} {
           set syb_home [lindex [split $syb_home :] 5]
       } else {
           set syb_home ""
       }
       }
   } else {
       set syb_home $env(SYBASE)
   }
 
   if {[string length $syb_home] > 0} {
     set intFile $syb_home/interfaces
    set serverList ""
    if [file isfile $intFile] {
      set ierr [catch {set fd [open $intFile]}]
      if {$ierr} {echo "error opening $intFile"}
      set sc [scancontext create]
      scanmatch -nocase $sc {^[a-z]} {lappend serverList $matchInfo(line)}
      scanfile $sc $fd
      close $fd
    } else {
      set serverList SYBASE
    }
  } else {
    puts stderr "SORRY cannot find SYBASE home dir by any means."
    puts stderr "      No envar SYBASE found."
    puts stderr "      No login dir for user sybase found in NIS or passwd file."
    exit 1
  }

  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 -show * -text pw -background ivory
  label .s.p.p   -text "  Password" -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 -activebackground lavender -activeforeground magenta2
  menu .s.s.s.m -background lavender
  foreach s $serverList {
    .s.s.s.m add command -label $s -command ".s.s.ser delete 0 end; .s.s.ser insert 0 $s " -background lavender -activebackground lavender -activeforeground magenta2
  }

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

  frame .s.b -background bisque
  button .s.b.ok  -text "Sign on"       -command {SYBtryConnect [.s.i.uname get] [.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 black -activeforeground yellow -foreground red

  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] DSQUERY] >= 0} {
    .s.s.ser insert 0 $env(DSQUERY)
  } else {
    .s.s.ser insert 0 SYBASE
  }

  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
  }

}

