proc makeEZrpt {} {

global server uname base table 
global bitmapdir DB
  global MsgW

##------------------------ pseudo-globals -- level 0 state vars

upvar #0 EZRcols cols
upvar #0 EZRcolatts colatts
upvar #0 EZRwhere where
upvar #0 EZRsorts sorts
upvar #0 EZRprints prints
upvar #0 EZRnumsrt numsrt
upvar #0 EZRnumprt numprt
upvar #0 EZRnumcol numcol
upvar #0 EZRporder porder
upvar #0 EZRsorder sorder
upvar #0 EZRop op
upvar #0 EZRcol col
upvar #0 EZRind ind
upvar #0 EZRcomp1 comp1
upvar #0 EZRcomp2 comp2
upvar #0 EZRsqlcmd sqlcmd
upvar #0 EZRdist dist
upvar #0 EZRrform rf

#	When we are invoked we forget anything we ever knew before

# puts stderr "Forget everything from earlier EZrpt..."
clearEZrpt

##------------------------

#	Don't even paint the window until you know you have a database and
#	table selected.

	if {($base == "") || ($table == "")} {
		.m.mb.ez flash
    		catch {setMsg $MsgW "EZrpt cannot be used until you select a database and table"}
		return
	}

	set sel [${DB}chkPriv $table sel]
	if {[lindex $sel 0] == "ERROR"} {
		catch {.m.mb.mkRpt flash}
                catch {setMsg $MsgW "Serious problem: $sel"}
		return
	}
	if {$sel == "NO"} {
		catch {.m.mb.mkRpt flash}
		catch {setMsg $MsgW "EZrpt cannot be run on table $table in database $base because you ($uname) do not have privilege to read that table"}
		return
	}

    	set w .ezrpt
	set rf $w
    	catch {destroy $w}
    	toplevel $w -class Dialog
    	wm title $w "EZrpt"
    	wm iconname $w "EZrpt!"
  	wm iconbitmap $w @$bitmapdir/ezrpt.xbm

	set minwidth 850
	set minheight 540
	wm geometry $w ${minwidth}x${minheight}
	wm minsize $w ${minwidth} ${minheight}

#	Get the current base and table by snarfing them out of the
#	informational display header -- thus not touching orig wisql.
#	Now, stylistically, I could get these strings the same way 
#	whenever I need them in sub procedures, or I could do what 
#	I did here and make them global.  I wonder which is really better.

#	Try to keep refs to poindexter code OUT of here!
#	set base [.m.title.cb get]
#	set table [.m.title.ct get]
	
# Now for testing we'll read in from a file instead of parsing syb output
#

	${DB}getEZcols R

	set TableName "$table"
	
# start at col 0 always
 
set col [lindex $cols 0]
set type [keylget colatts($col) type]

if {($type == "char" ) || ($type == "varchar")} {
	set size [keylget colatts($col) size]
	set type [format "%s(%s)" $type $size]
}
set ind 0

# make canvas pic a child of .data frame (lower portion of window)

label $w.spacer -relief flat -border 0 -text "" -background antiquewhite
frame $w.data -relief flat -border 0 -background antiquewhite
frame $w.data.spec -relief groove -border 2 -width 150 -background antiquewhite
canvas $w.data.pic -relief flat -borderwidth 2 -yscrollcommand "$w.data.sbv set" -background antiquewhite
# canvas $w.data.pic -relief flat -borderwidth 2 -width [expr $width - 150]   #	-yscroll "$w.data.sbv set" 

# make a frame that will go inside the canvas (the canvas is just so
# we can have scroll bars for the whole window)
frame $w.data.pic.win -relief flat -border 0 -background antiquewhite
frame $w.data.pic.win.winL -relief flat -border 0 -background antiquewhite
frame $w.data.pic.win.winR -relief flat -border 0 -background antiquewhite

set font [getFont $w messagehel]
#	and a nice wide message to hold message info
message $w.messages -width $minwidth -aspect 3000 -relief raised -border 1  -font $font  -text "Select a comparison operator . . ." -background bisque
bind $w.messages <Control-1> "ezHelp Messages; break"

#	the frame ..data.spec is tall and narrow with a huge list of
#	nifty thingies in it.
set font [getFont $w messageheli]
label $w.data.spec.fld -text "selected field:" -relief raised -border 0  -font $font -background antiquewhite
label $w.data.spec.cf -text "$col" -relief groove -border 2 -background antiquewhite
label $w.data.spec.type -text "($type)" -relief groove -border 2 -background antiquewhite
bind $w.data.spec.cf <Control-1> "ezHelp fieldname; break"
bind $w.data.spec.type <Control-1> "ezHelp type; break"

button $w.data.spec.all -text "ALL" -relief raised -border 1  -command "prtAll $w" -padx 0 -pady 0 -background azure -activebackground azure -activeforeground orange 
checkbutton $w.data.spec.uni -text "UNIQUE" -relief raised -border 1  -variable EZRdist -padx 0 -pady 0 -background azure -activebackground azure -activeforeground orange -selectcolor orange
bind $w.data.spec.all <Control-1> "ezHelp EZRall; break"
bind $w.data.spec.uni <Control-1> "ezHelp EZRuni; break"

label $w.data.spec.require -text "should be:" -relief raised -border 0  -font $font -background antiquewhite

entry $w.data.spec.cmp1 -width 10 -relief sunken -border 1 -text EZRcomp1 -background ivory
set font [getFont $w messagehel]
label $w.data.spec.and -text " "  -font $font -relief raised -border 0 -background antiquewhite
entry $w.data.spec.cmp2 -width 10 -relief sunken -border 0 -text EZRcomp2 -background ivory
bind $w.data.spec.cmp1 <Control-1> "ezHelp EZRcmp1; break"
bind $w.data.spec.and <Control-1> "ezHelp EZRand; break"
bind $w.data.spec.cmp2 <Control-1> "ezHelp EZRcmp2; break"

entry $w.data.spec.wid -width 3 -relief sunken -border 1  -background ivory
set font [getFont $w helvetica]
label $w.data.spec.lwid -text "Constrain Width To:" -font $font -relief sunken -border 0 -background antiquewhite
bind $w.data.spec.wid <Return> "ezRwidth $w.data.spec.wid"
bind $w.data.spec.wid <Control-1> "ezHelp EZRwid; break"

button $w.data.spec.go -text "OK" -command "mkSelect EZR $w; chkEZRsel $w {}"  -width 15 -relief raised -border 2 -padx 0 -pady 0 -background lavender -activeforeground lavender -activeforeground magenta2

#
set font [getFont $w banneri]
entry $w.data.spec.gop -text "" -font $font -relief sunken -border 0 \
	-background bisque -textvariable EZRop -state disabled -justify center
set font [getFont $w mediumhelb]
menubutton $w.data.spec.bool -text Comparison... -menu $w.data.spec.bool.m  -background azure -relief raised -border 2 -activebackground azure -activeforeground magenta2
set m [menu $w.data.spec.bool.m -tearoff 0 -background azure] 
$m add radio -label "=" -variable EZRop -value "="  -font $font -background azure -command "chkOp $w eq =" -background azure -activebackground azure -activeforeground magenta2 -selectcolor magenta2
$m add radio  -label "!=" -variable EZRop -value "!="  -font $font  -background azure -command "chkOp $w ne !=" -background azure -activebackground azure -activeforeground magenta2 -selectcolor magenta2
$m add radio  -label ">" -variable EZRop -value ">"  -font $font  -background azure -command "chkOp $w gt >" -background azure -activebackground azure -activeforeground magenta2 -selectcolor magenta2
$m add radio  -label "<" -variable EZRop -value "<"  -font $font  -background azure -command "chkOp $w lt <" -background azure -activebackground azure -activeforeground magenta2 -selectcolor magenta2
$m add radio  -label ">=" -variable EZRop -value ">="  -font $font  -background azure -command "chkOp $w ge >=" -background azure -activebackground azure -activeforeground magenta2 -selectcolor magenta2
$m add radio  -label "<=" -variable EZRop -value "<="  -font $font  -background azure -command "chkOp $w le <=" -background azure -activebackground azure -activeforeground magenta2 -selectcolor magenta2
$m add radio  -label "BETWEEN" -variable EZRop -value "bet"  -font $font  -background azure -command "chkOp $w bt bet" -background azure -activebackground azure -activeforeground magenta2 -selectcolor magenta2
$m add radio  -label "STARTS" -variable EZRop -value "sta"  -font $font  -background azure -command "chkOp $w st sta" -background azure -activebackground azure -activeforeground magenta2 -selectcolor magenta2
$m add radio  -label "CONT" -variable EZRop -value "con"  -font $font  -background azure -command "chkOp $w ct con" -background azure -activebackground azure -activeforeground magenta2 -selectcolor magenta2
$m add radio  -label "ENDS" -variable EZRop -value "end"  -font $font  -background azure -command "chkOp $w en end" -background azure -activebackground azure -activeforeground magenta2 -selectcolor magenta2
$m add radio  -label "IN" -variable EZRop -value "in"  -font $font  -background azure -command "chkOp $w in in" -background azure -activebackground azure -activeforeground magenta2 -selectcolor magenta2
#

pack $w.data.spec.all -side top -fill x -ipady 2
pack $w.data.spec.uni -side top -fill x -ipady 2
pack $w.data.spec.fld -side top -fill x -ipady 10
pack $w.data.spec.cf -side top -fill x -ipady 2
pack $w.data.spec.type -side top -fill x -ipady 2
pack $w.data.spec.require -side top -fill x -ipady 10
pack $w.data.spec.bool -side top -fill x -ipady 2 
pack $w.data.spec.gop -side top -fill x -ipady 2 
pack $w.data.spec.cmp1 -side top -fill x -ipady 2
pack $w.data.spec.and -side top -fill x -ipady 2
pack $w.data.spec.cmp2 -side top -fill x -ipady 2
pack $w.data.spec.go -side top -fill x -ipady 20
pack $w.data.spec.wid -side bottom -fill x -ipady 2
pack $w.data.spec.lwid -side bottom -fill x -ipady 2
 
        bind $w.data.spec.bool <Control-1> "ezHelp Booleans; break"

frame $w.control -relief raised -border 0 -background bisque
button $w.control.quit -text "GO AWAY" -command "destroy $w"  -padx 1 -pady 1 -background white -foreground red -activebackground black -activeforeground yellow
button $w.control.go -text "TRANSFER" -command "putSQL $w" -padx 1 -pady 1 -background lemonchiffon -activebackground orange
button $w.control.seeSQL -text "SEE SQL" -command "seeSQL $w" -padx 1 -pady 1 -background lavender -activebackground lavender -activeforeground magenta2
#
menubutton $w.control.help -text "Help..." -menu $w.control.help.m  -relief raised -border 1 -padx 1 -pady 1 -background lavender -activebackground lavender -activeforeground magenta2
menu $w.control.help.m -background lavender
$w.control.help.m add command -label "General" -command "ezHelp EZRgen" -background lavender -activebackground lavender -activeforeground magenta2
$w.control.help.m add command -label "FastKeys" -command "ezHelp EZRkeys" -background lavender -activebackground lavender -activeforeground magenta2
$w.control.help.m add command -label "HowTo" -command "ezHelp EZRhow" -background lavender -activebackground lavender -activeforeground magenta2
#
button $w.control.count -text "COUNT" -command "ezCount $w.messages" -padx 0 -pady 0 -background lavender -background lavender -activebackground lavender -activeforeground magenta2
button $w.control.form -text "FORM" -command "ezRForm $w" -padx 0 -pady 0 -background lavender -background lavender -activebackground lavender -activeforeground magenta2

bind $w.control.quit <Control-1> "ezHelp Quit; break"
bind $w.control.go <Control-1> "ezHelp EZRgo; break"
bind $w.control.seeSQL <Control-1> "ezHelp EZRsql; break"
bind $w.control.count <Control-1> "ezHelp EZRcnt; break"
bind $w.control.form <Control-1> "ezHelp EZRfrm; break"
bind $w.control.help <Control-1> "ezHelp ToolHlp; break"

label $w.control.dbtb -text "$base.$table"  -relief groove -border 2 -background antiquewhite
bind $w.control.dbtb <Control-1> "ezHelp table; break"

set font [getFont $w messageheli]
label $w.control.tbl -text "table" -relief groove -border 2  -font $font -background antiquewhite

pack $w.control.tbl $w.control.dbtb -side left 
pack $w.control.quit -side right  
pack $w.control.go -side right -ipadx 30
pack $w.control.seeSQL -side right -ipadx 30
pack $w.control.count -side right -ipadx 30
pack $w.control.form -side right -ipadx 30
pack $w.control.help -side right -ipadx 50
 



# Then foreach field, make a row of widgets
set i 0
foreach c $cols {
	
keylset colatts($c) width 0

frame $w.data.pic.win.winL.$c -relief flat -borderwidth 0 -background antiquewhite
frame $w.data.pic.win.winR.$c -relief flat -borderwidth 0 -background antiquewhite

checkbutton $w.data.pic.win.winL.$c.pb -text "print"  -variable EZRgorp($c) -relief flat -border 1 -background antiquewhite -activebackground antiquewhite -activeforeground magenta2 -selectcolor gray75
entry $w.data.pic.win.winL.$c.po -relief sunken -width 3 -background ivory
radiobutton $w.data.pic.win.winL.$c.cc -text "$c" -relief flat  -variable EZRcol -value "$c"  -border 1 -background antiquewhite -activebackground antiquewhite -activeforeground magenta2 -selectcolor gray75
entry $w.data.pic.win.winR.$c.st -relief sunken -width 35 -background ivory

# if I was saving query text from here it might be useful, but the
# query gets saved from the main wisql window, so forget this

radiobutton $w.data.pic.win.winR.$c.a -text "sortAsc" -relief flat  -variable EZRgors($c) -value "a" -border 1 -background antiquewhite -activebackground antiquewhite -activeforeground magenta2 -selectcolor gray75
radiobutton $w.data.pic.win.winR.$c.d -text "sortDesc" -relief flat  -variable EZRgors($c) -value "d" -border 1 -background antiquewhite -activebackground antiquewhite -activeforeground magenta2 -selectcolor gray75
entry $w.data.pic.win.winR.$c.so -relief sunken -width 3 -background ivory

bind $w.data.pic.win.winL.$c.pb <Control-1> "ezHelp EZRpr; break"
bind $w.data.pic.win.winL.$c.po <Control-1> "ezHelp EZRpr; break"
bind $w.data.pic.win.winL.$c.cc <Control-1> "ezHelp EZRfield; break"
bind $w.data.pic.win.winL.$c.cc <Control-2> "dataHelp $table $c; break"
bind $w.data.pic.win.winR.$c.st <Control-1> "ezHelp EZRreq; break"
bind $w.data.pic.win.winR.$c.a <Control-1> "ezHelp EZRsort; break"
bind $w.data.pic.win.winR.$c.d <Control-1> "ezHelp EZRsort; break"
bind $w.data.pic.win.winR.$c.so <Control-1> "ezHelp EZRsort; break"

bind $w.data.pic.win.winL.$c.cc <ButtonRelease-1>  "colCurrent $w $c"
bind $w.data.pic.win.winL.$c.pb <ButtonRelease-1>  " setPrint $w $c"
bind $w.data.pic.win.winL.$c.po <Leave>  "setOrder $w $c EZRprints EZRporder EZRnumprt EZRcols EZRscols"
bind $w.data.pic.win.winR.$c.st <Leave>  "chkEZRsel $w $c"
bind $w.data.pic.win.winR.$c.a <ButtonRelease-1>  " setSort $w $c a"
bind $w.data.pic.win.winR.$c.d <ButtonRelease-1>  " setSort $w $c d"
bind $w.data.pic.win.winR.$c.so <Leave>  "setOrder $w $c EZRsorts EZRsorder EZRnumsrt EZRcols EZRscols"

pack $w.data.pic.win.winL.$c.pb -side left -fill x -anchor w
pack $w.data.pic.win.winL.$c.po -side left -fill x -anchor w
pack $w.data.pic.win.winL.$c.cc -side left -fill x -anchor w
 
pack $w.data.pic.win.winR.$c.st -side left -fill x -anchor w
pack $w.data.pic.win.winR.$c.a -side left -fill x -anchor w
pack $w.data.pic.win.winR.$c.d -side left -fill x -anchor w
pack $w.data.pic.win.winR.$c.so -side left -fill x -anchor w


append Lpack "$w.data.pic.win.winL.$c "
append Rpack "$w.data.pic.win.winR.$c "

set prints($c) 0
set sorts($c) 0

incr i

}

append Lpack "-side top -anchor nw"
append Rpack "-side top -anchor nw"

set numcol $i

scrollbar $w.data.sbv -width 15 -orient vertical  -command "$w.data.pic yview" -relief sunken -background ivory -activebackground mistyrose -troughcolor bisque
bind $w.data.sbv <Control-1> "ezHelp Scrollbars; break"

eval "pack $Lpack" 
eval "pack $Rpack" 

pack $w.data.pic.win.winL $w.data.pic.win.winR -side left

$w.data.pic create window 2 2 -anchor nw -window $w.data.pic.win

pack $w.data.spec -side left -fill y
pack $w.data.pic -side left -expand true -fill both
pack $w.data.sbv -side left -fill y
 
pack $w.spacer -side bottom
pack $w.control -side top -fill x -ipady 10
pack $w.messages -side top -fill x -ipady 10
pack $w.data -side top -expand true -fill both -ipady 10
 

#	used to follow sbv
#	$w.sbh {bot -fill x -ipady 2} 

	update

	set datah [winfo height $w.data.pic.win ]
	set dataw [winfo width $w.data.pic.win ]
#	example of setting limits to canvas scrolling
#	canvas $c -scrollregion {-10c -10c 50c 20c}
	eval $w.data.pic configure -scrollregion \{-10 -10 200 [expr {$datah + 10}] \}

colCurrent $w [lindex $cols 0] 
# .pic.win.winL.[lindex $cols 0].pb invoke

focus $w
}

