Source code for the Tcl/Tk Rolodex client. This application assumes that spynergy.tcl is in the launch directory.





# --------------------------------------------------------------
# roloclnt.tcl -- Rolodex Internet client
#  by Mike Doyle
#
#  Copyright (c) 1997 Eolas Technologies Inc.
#  Freely modifiable/redistributable under the "Standard Tcl License"
#  See http://www.eolas.com/tcl/license.txt for details
#    modified by Hengbing Duan 
#    on Sept. 02, 1997
### 

########################################################
#  Start GUI definition


source spynergy.tcl
global db dir result seqno current_type person_name host port server
set result 0
set seqno 0
set dir [pwd]   
set port 8088
# server ip or host name
set server localhost    

set person_name ""

bind Entry  {tkEntryBackspace %W}

set Parent .rolodex
frame $Parent -background gray40
set Name $Parent.buttons
frame $Name -background gray40
pack $Name -expand 0 -fill x

set Name $Parent.buttons.connect
button $Name     -activebackground  gray80 \
    -activeforeground black \
    -background gray40 \
    -command connect \
    -disabledforeground green \
    -foreground white -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -padx 5 \
    -pady 1 \
    -text "Connect"
pack $Name     -anchor nw \
    -fill none \
    -side left

set Name $Parent.buttons.first
button $Name     -activebackground  gray80 \
    -activeforeground black \
    -background gray40 \
    -command {
	disable_buttons
	set seqno 1
	dp_RPC $host db_get_row $seqno     
	db_display_record   
	enable_buttons           
	} \
    -disabledforeground LightGray \
    -foreground White -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -padx 5 \
    -pady 1 \
    -text "<<"
pack $Name     -anchor nw \
    -fill none \
    -side left

set Name $Parent.buttons.back
button $Name     -activebackground  gray80 \
    -activeforeground black \
    -background gray40 \
    -command {
	disable_buttons
	set row [dp_RPC $host db_prev_row]
	if {$row} {
            set seqno $row
  		dp_RPC $host db_get_row $seqno
		db_display_record
		}
	enable_buttons
	} \
    -disabledforeground LightGray \
    -foreground White -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -padx 5 \
    -pady 1 \
    -text "<"
pack $Name     -anchor nw \
    -fill none \
    -side left

set Name $Parent.buttons.forward
button $Name     -activebackground  gray80 \
    -activeforeground black \
    -background gray40 \
    -command {
	disable_buttons
	set row [dp_RPC $host db_next_row]
	if {$row} {set seqno $row}
	if { $row} {
		dp_RPC $host db_get_row $seqno
		db_display_record
		}
	enable_buttons
	} \
    -disabledforeground LightGray \
    -foreground White -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -padx 5 \
    -pady 1 \
    -text ">"
pack $Name     -anchor nw \
    -fill none \
    -side left

set Name $Parent.buttons.last
button $Name     -activebackground  gray80 \
    -activeforeground black \
    -background gray40 \
    -command {
	disable_buttons
	set seqno [dp_RPC $host db_last_row]
 	db_display_record
	enable_buttons
	} \
    -disabledforeground LightGray \
    -foreground White -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -padx 5 \
    -pady 1 \
    -text ">>"
pack $Name     -anchor nw \
    -fill none \
    -side left

set Name $Parent.buttons.sort
button $Name     -activebackground  gray80 \
    -activeforeground black \
    -background gray40 \
    -command { 
	disable_buttons
	dp_RPC $host db_sort
	db_display_record 
	enable_buttons
	} \
    -disabledforeground LightGray \
    -foreground White -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -padx 5 \
    -pady 1 \
    -text "Sort"
pack $Name     -anchor nw \
    -fill none \
    -side left

set Name $Parent.buttons.spacer
label $Name -text " " -background gray40
pack $Name -anchor nw -side left

set Name $Parent.buttons.new_record
button $Name     -activebackground  gray80 \
    -activeforeground black \
    -background gray40 \
    -command {
	disable_buttons
	$Parent.datatype.personal invoke
	db_clear_form
	pack forget $Parent.buttons.new_record
	pack $Parent.buttons.new_record_done -fill none -side left -before $Parent.buttons.get_name
	enable_buttons
} \
    -disabledforeground LightGray \
    -foreground White -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -padx 5 \
    -pady 1 \
    -text "New Record"
pack $Name     -anchor nw \
    -fill none \
    -side left

set Name $Parent.buttons.new_record_done
button $Name     -activebackground  gray80 \
    -activeforeground black \
    -background gray60 -relief groove -border 1\
    -command {
	disable_buttons
	db_add_record; 
	db_clear_form; 
	pack forget $Parent.buttons.new_record_done
	pack $Parent.buttons.new_record -fill none -side left -before $Parent.buttons.get_name
	after 1000 db_display_record
	enable_buttons
	} \
    -disabledforeground LightGray \
    -foreground Black -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -padx 5 \
    -pady 1 \
    -text "      Done      "

set Name $Parent.buttons.get_name
button $Name     -activebackground  gray80 \
    -activeforeground black \
    -background gray40 \
    -command {
	disable_buttons
	db_get_name
	enable_buttons
	} \
    -disabledforeground LightGray \
    -foreground White -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -padx 5 \
    -pady 1 \
    -text "Search Name"
pack $Name     -anchor nw \
    -fill none \
    -side left

set Name $Parent.buttons.modify_record
button $Name     -activebackground  gray80 \
    -activeforeground black \
    -background gray40 \
    -command {
	disable_buttons
	db_capture_record
	dp_RPC $host db_put_row
	db_clear_form
	after 1000 db_display_record
	enable_buttons
	} \
    -disabledforeground LightGray \
    -foreground White -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -padx 5 \
    -pady 1 \
    -text "Modify Record"
pack $Name     -anchor nw \
    -fill none \
    -side left

set Name $Parent.buttons.delete_record
button $Name     -activebackground  gray80 \
    -activeforeground black \
    -background gray40 \
    -command {
	disable_buttons
	if {$seqno} {
		dp_RPC $host db_del_row $seqno
		db_clear_form
		.rolodex.form.spacer0.data configure -text ""
		} 
	enable_buttons
	} \
    -disabledforeground LightGray \
    -foreground White -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -padx 5 \
    -pady 1 \
    -text "Delete Record"
pack $Name     -anchor nw \
    -fill none \
    -side left

set Name $Parent.buttons.spacer2
label $Name -text "       " -background gray40
pack $Name -anchor nw -side left

set Name $Parent.buttons.exit
button $Name     -activebackground  gray80 \
    -activeforeground black \
    -background gray40 \
    -command {
	disable_buttons
        dp_RPC $host db_close
	dp_CloseRPC $host
        exit} \
    -disabledforeground LightGray \
    -foreground White -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -padx 5 \
    -pady 1 \
    -text "Exit"
pack $Name     -anchor nw \
    -fill none \
    -side right

#############################################
# Data Type Buttons
#

set Name $Parent.datatype
frame $Name 
pack $Name -expand 0 -fill x

set Name $Parent.datatype.personal
button $Name     -activebackground white \
    -activeforeground black \
    -background white -relief flat \
    -command {
	$Parent.datatype.$current_type configure -background gray40 -relief sunken -foreground white \
		-activebackground gray80
	$Parent.datatype.personal configure -background white -relief flat -foreground black \
		-activebackground white
	pack forget $Parent.form.$current_type
	pack $Parent.form.personal  -anchor nw -expand 0 -fill x -before $Parent.form.notes
	set current_type personal	

	} \
    -disabledforeground LightGray \
    -foreground black -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -pady 1 \
    -text "Personal"
pack $Name   -expand 1  -anchor nw  -fill x  -side left

set Name $Parent.datatype.work
button $Name     -activebackground gray80  \
    -activeforeground black \
    -background gray40  -relief sunken \
    -command {
	$Parent.datatype.$current_type configure -background gray40 -relief sunken -foreground white \
		-activebackground gray80
	$Parent.datatype.work configure -background white -relief flat -foreground black \
		-activebackground white
	pack forget $Parent.form.$current_type
	pack $Parent.form.work  -anchor nw -expand 0 -fill x -before $Parent.form.notes	
	set current_type work

	} \
    -disabledforeground LightGray \
    -foreground White -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -pady 1 \
    -text "Work"
pack $Name   -expand 1  -anchor nw  -fill x  -side left

set Name $Parent.datatype.internet
button $Name     -activebackground gray80 \
    -activeforeground black \
    -background gray40 -relief sunken \
    -command {
	$Parent.datatype.$current_type configure -background gray40 -relief sunken -foreground white \
		-activebackground gray80
	$Parent.datatype.internet configure -background white -relief flat -foreground black \
		-activebackground white
	pack forget $Parent.form.$current_type
	pack $Parent.form.internet  -anchor nw -expand 0 -fill x -before $Parent.form.notes	
	set current_type internet

	} \
    -disabledforeground LightGray \
    -foreground White -highlightthickness 0 \
    -highlightbackground LightGray \
    -highlightcolor LightGray \
    -pady 1 \
    -text "Internet"
pack $Name   -expand 1  -anchor nw  -fill x  -side left

set Name $Parent.form
frame $Name -background white
pack $Name -anchor nw -expand 1 -fill both
frame $Parent.form.spacer0  -background white -relief flat -border 0
pack $Parent.form.spacer0 -expand 0 -fill x
label $Parent.form.spacer0.name -text "Data Record for:" -background white -foreground black
pack $Parent.form.spacer0.name -side left -anchor w
label $Parent.form.spacer0.data -text  " " -background white -foreground black
pack $Parent.form.spacer0.data -side left -anchor w
frame $Parent.form.spacer1 -height 2 -background gray40
pack $Parent.form.spacer1 -expand 0 -fill x

###############################################
#  Personal data area
#
set Form $Parent.form.personal
set Name $Form
frame $Name -background white -borderwidth 2 -relief groove 
pack $Name -anchor nw -expand 0 -fill x

set Name $Form.name
frame $Name -background white 
pack $Name -anchor nw -expand 1 -fill x -side top

set Name $Form.name.label
label $Name -text "Name:  " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.name.entry
entry $Name -width 91 -background lightgray -highlightthickness 0 
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x

set Name $Form.street
frame $Name -background white 
pack $Name -anchor nw -expand 1 -fill x -side top

set Name $Form.street.label
label $Name -text "Street:  " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.street.entry
entry $Name -width 91 -background lightgray -highlightthickness 0 
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x

set Name $Form.citystate
frame $Name -background white 
pack $Name -anchor nw -expand 1 -fill x -side top

set Name $Form.citystate.city_l
label $Name -text "City:     " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.citystate.city
entry $Name -width 50 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2

set Name $Form.citystate.state_l
label $Name -text "State:  " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.citystate.state
entry $Name -width 5 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2

set Name $Form.citystate.zip_l
label $Name -text "  Zip:  " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.citystate.zip
entry $Name -width 21 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x

set Name $Form.phonefax
frame $Name  -background white 
pack $Name -anchor nw -expand 1 -fill x -side top

set Name $Form.phonefax.phone_l
label $Name -text "Phone: " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.phonefax.phone
entry $Name -width 24 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2

set Name $Form.phonefax.fax_l
label $Name -text "  Fax:  " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.phonefax.fax
entry $Name -width 24 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2

set Name $Form.phonefax.cellular_l
label $Name -text "  Cellular:  " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.phonefax.cellular
entry $Name -width 25 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x


########################
#  Work data area
#

set Form $Parent.form.work
set Name $Form
frame $Name -background white -borderwidth 2 -relief groove
#pack $Name -anchor nw -expand 0 -fill x

set Name $Form.name
frame $Name -background white 
pack $Name -anchor nw -expand 1 -fill x -side top

set Name $Form.name.label
label $Name -text "Company: " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.name.entry
entry $Name -width 89 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x

set Name $Form.street
frame $Name -background white 
pack $Name -anchor nw -expand 1 -fill x -side top

set Name $Form.street.label
label $Name -text "Street:      " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.street.entry
entry $Name -width 89 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x

set Name $Form.citystate
frame $Name -background white 
pack $Name -anchor nw -expand 1 -fill x -side top

set Name $Form.citystate.city_l
label $Name -text "City:          " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.citystate.city
entry $Name -width 50 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2

set Name $Form.citystate.state_l
label $Name -text "State:  " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.citystate.state
entry $Name -width 5 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2

set Name $Form.citystate.zip_l
label $Name -text " Zip:  " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.citystate.zip
entry $Name -width 19 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x

set Name $Form.phonefax
frame $Name  -background white 
pack $Name -anchor nw -expand 1 -fill x -side top

set Name $Form.phonefax.phone_l
label $Name -text "Phone:     " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.phonefax.phone
entry $Name -width 24 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2

set Name $Form.phonefax.fax_l
label $Name -text "  Fax:  " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.phonefax.fax
entry $Name -width 24 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2

set Name $Form.phonefax.cellular_l
label $Name -text "  Cellular:  " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.phonefax.cellular
entry $Name -width 23 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x


########################
#  Internet data area
#

set Form $Parent.form.internet
set Name $Form
frame $Name -background white -borderwidth 2 -relief groove
#pack $Name -anchor nw -expand 0 -fill x

set Name $Form.email
frame $Name -background white 
pack $Name -anchor nw -expand 1 -fill x -side top

set Name $Form.email.label
label $Name -text "Email:   " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.email.entry
entry $Name -width 91 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x

set Name $Form.personal_web
frame $Name -background white 
pack $Name -anchor nw -expand 1 -fill x -side top

set Name $Form.personal_web.label
label $Name -text "Personal Web Site:    " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.personal_web.url
entry $Name -width 80 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x

set Name $Form.work_web
frame $Name -background white 
pack $Name -anchor nw -expand 1 -fill x -side top

set Name $Form.work_web.label
label $Name -text "Work Web Site:         " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.work_web.url
entry $Name -width 80 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x

set Name $Form.pagerpgp
frame $Name  -background white 
pack $Name -anchor nw -expand 1 -fill x -side top

set Name $Form.pagerpgp.pager_l
label $Name -text "Pager:  " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.pagerpgp.pager
entry $Name -width 24 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2

set Name $Form.pagerpgp.pgp_l
label $Name -text "   PGP Fingerprint: " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.pagerpgp.pgp

entry $Name -width 50 -background lightgray -highlightthickness 0  
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x


###########################################
# Notes Area
#

set Form $Parent.form.notes
set Name $Form
frame $Name -background white -borderwidth 2 -relief groove
pack $Name -anchor nw -expand 1 -fill both

set Name $Form.misc
frame $Name  -background white 
pack $Name -anchor nw -expand 0 -fill x -side top

set Name $Form.misc.scroll
scrollbar $Name -command {$Form.misc.data yview} -orient vertical
pack $Name -anchor ne -side right -padx 4 -pady 2 -expand 0 -fill y

set Name $Form.misc.data_l
label $Name -text "  Misc data:" -background white 
pack $Name -anchor nw -side left -pady 2

set Name $Form.misc.data
text $Name -width 80 -background gray90 -borderwidth 3 -height 4 -width 84 \
	-yscrollcommand {.rolodex.form.notes.misc.scroll set} \
	 -highlightthickness 0 
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill x


set Name $Form.scroll
scrollbar $Name -command {$Form.text yview} -orient vertical
pack $Name -anchor ne -side right -padx 4 -pady 2 -expand 0 -fill y

set Name $Form.text_l
label $Name -text "   Notes:   " -background white
pack $Name -anchor nw -side left -pady 2

set Name $Form.text
text $Name -width 45 -background gray90 -borderwidth 3 -height 10 -width 85 \
   -yscrollcommand {$Form.scroll set}  -highlightthickness 0 
pack $Name -anchor nw -side left -pady 2 -expand 1 -fill both
########################
# Put it up
#

set current_type personal
pack $Parent -expand 1 -fill both

#### call rpc, question, muti-user? data concurrency? sychronization?
# dp_RPC $host db_open

### db_display_record should be in the client side ,
### but the data retrieval part needs to be replaced by a RPC call
### also a corresponding db_getfield() should be included in the server
###  
proc db_display_record {} {
   global db person_name host	
	.rolodex.form.personal.name.entry delete 0 end
	.rolodex.form.personal.name.entry insert end [dp_RPC $host db_getfield NAME]
	.rolodex.form.personal.street.entry delete 0 end
	.rolodex.form.personal.street.entry insert end [dp_RPC $host db_getfield STREET]
	.rolodex.form.personal.citystate.city delete 0 end
	.rolodex.form.personal.citystate.city insert end [dp_RPC $host db_getfield CITY]
	.rolodex.form.personal.citystate.state delete 0 end
	.rolodex.form.personal.citystate.state insert end [dp_RPC $host db_getfield STATE]
	.rolodex.form.personal.citystate.zip delete 0 end
	.rolodex.form.personal.citystate.zip insert end [dp_RPC $host db_getfield ZIP]
	.rolodex.form.personal.phonefax.phone delete 0 end
	.rolodex.form.personal.phonefax.phone insert end [dp_RPC $host db_getfield PHONE]
	.rolodex.form.personal.phonefax.fax  delete 0 end
	.rolodex.form.personal.phonefax.fax insert end [dp_RPC $host db_getfield FAX]
	.rolodex.form.personal.phonefax.cellular delete 0 end
	.rolodex.form.personal.phonefax.cellular insert end [dp_RPC $host db_getfield CELL]
	.rolodex.form.work.name.entry delete 0 end
	.rolodex.form.work.name.entry insert end [dp_RPC $host db_getfield COMPANY]
	.rolodex.form.work.street.entry delete 0 end
	.rolodex.form.work.street.entry insert end [dp_RPC $host db_getfield C_STREET]
	.rolodex.form.work.citystate.city delete 0 end
	.rolodex.form.work.citystate.city insert end [dp_RPC $host db_getfield C_CITY]
	.rolodex.form.work.citystate.state delete 0 end
	.rolodex.form.work.citystate.state insert end [dp_RPC $host db_getfield C_STATE]
	.rolodex.form.work.citystate.zip delete 0 end
	.rolodex.form.work.citystate.zip insert end [dp_RPC $host db_getfield C_ZIP]
	.rolodex.form.work.phonefax.phone delete 0 end
	.rolodex.form.work.phonefax.phone insert end [dp_RPC $host db_getfield C_PHONE]
	.rolodex.form.work.phonefax.fax delete 0 end
	.rolodex.form.work.phonefax.fax insert end [dp_RPC $host db_getfield C_FAX]
	.rolodex.form.work.phonefax.cellular delete 0 end
	.rolodex.form.work.phonefax.cellular insert end [dp_RPC $host db_getfield C_CELL]
	.rolodex.form.internet.email.entry delete 0 end
	.rolodex.form.internet.email.entry insert end [dp_RPC $host db_getfield EMAIL]
	.rolodex.form.internet.personal_web.url delete 0 end
	.rolodex.form.internet.personal_web.url insert end [dp_RPC $host db_getfield PERSONALWEB]
	.rolodex.form.internet.work_web.url delete 0 end
	.rolodex.form.internet.work_web.url insert end [dp_RPC $host db_getfield WORKWEB]
	.rolodex.form.internet.pagerpgp.pager delete 0 end
	.rolodex.form.internet.pagerpgp.pager insert end [dp_RPC $host db_getfield PAGER]
	.rolodex.form.internet.pagerpgp.pgp delete 0 end
	.rolodex.form.internet.pagerpgp.pgp insert end [dp_RPC $host db_getfield PGPFINGERPRINT]
	.rolodex.form.notes.misc.data delete 1.0 end
	.rolodex.form.notes.misc.data insert end [dp_RPC $host db_getfield PGPKEY]
	.rolodex.form.notes.text delete 1.0 end
	.rolodex.form.notes.text insert end [dp_RPC $host db_getfield NOTES]
      .rolodex.form.spacer0.data configure -text [.rolodex.form.personal.name.entry get]
}

#### call RPC to set value for a single field
proc db_capture_record {} {
  global host 
	dp_RPC $host db_setfield NAME [replace_space [.rolodex.form.personal.name.entry get]]
	dp_RPC $host db_setfield STREET [replace_space [.rolodex.form.personal.street.entry get]]
	dp_RPC $host db_setfield CITY [replace_space [.rolodex.form.personal.citystate.city get]]
	dp_RPC $host db_setfield STATE [replace_space [.rolodex.form.personal.citystate.state get]]
	dp_RPC $host db_setfield ZIP [replace_space [.rolodex.form.personal.citystate.zip get]]
	dp_RPC $host db_setfield PHONE [replace_space [.rolodex.form.personal.phonefax.phone get]]
	dp_RPC $host db_setfield FAX [replace_space [.rolodex.form.personal.phonefax.fax get]]
	dp_RPC $host db_setfield CELL [replace_space [.rolodex.form.personal.phonefax.cellular get]]
	dp_RPC $host db_setfield COMPANY [replace_space [.rolodex.form.work.name.entry get]]
	dp_RPC $host db_setfield C_STREET [replace_space [.rolodex.form.work.street.entry get]]
	dp_RPC $host db_setfield C_CITY [replace_space [.rolodex.form.work.citystate.city get]]
	dp_RPC $host db_setfield C_STATE [replace_space [.rolodex.form.work.citystate.state get]]
	dp_RPC $host db_setfield C_ZIP [replace_space [.rolodex.form.work.citystate.zip get]]
	dp_RPC $host db_setfield C_PHONE [replace_space [.rolodex.form.work.phonefax.phone get]]
	dp_RPC $host db_setfield C_FAX [replace_space [.rolodex.form.work.phonefax.fax get]]
	dp_RPC $host db_setfield C_CELL [replace_space [.rolodex.form.work.phonefax.cellular get]]
	dp_RPC $host db_setfield EMAIL [replace_space [.rolodex.form.internet.email.entry get]]
	dp_RPC $host db_setfield PERSONALWEB [replace_space [.rolodex.form.internet.personal_web.url get]]
	dp_RPC $host db_setfield WORKWEB [replace_space [.rolodex.form.internet.work_web.url get]]
	dp_RPC $host db_setfield PAGER [replace_space [.rolodex.form.internet.pagerpgp.pager get]]
	dp_RPC $host db_setfield PGPFINGERPRINT [replace_space [.rolodex.form.internet.pagerpgp.pgp get]]
	dp_RPC $host db_setfield PGPKEY [replace_space [.rolodex.form.notes.misc.data get 1.0 end]]
	dp_RPC $host db_setfield NOTES [replace_space [.rolodex.form.notes.text get 1.0 end]]
}

#### nothing changed for this function
proc db_clear_form {} {
	.rolodex.form.personal.name.entry delete 0 end
	.rolodex.form.personal.street.entry delete 0 end
	.rolodex.form.personal.citystate.city delete 0 end
	.rolodex.form.personal.citystate.state delete 0 end
	.rolodex.form.personal.citystate.zip delete 0 end
	.rolodex.form.personal.phonefax.phone delete 0 end
	.rolodex.form.personal.phonefax.fax  delete 0 end
	.rolodex.form.personal.phonefax.cellular delete 0 end
	.rolodex.form.work.name.entry delete 0 end
	.rolodex.form.work.street.entry delete 0 end
	.rolodex.form.work.citystate.city delete 0 end
	.rolodex.form.work.citystate.state delete 0 end
	.rolodex.form.work.citystate.zip delete 0 end
	.rolodex.form.work.phonefax.phone delete 0 end
	.rolodex.form.work.phonefax.fax delete 0 end
	.rolodex.form.work.phonefax.cellular delete 0 end
	.rolodex.form.internet.email.entry delete 0 end
	.rolodex.form.internet.personal_web.url delete 0 end
	.rolodex.form.internet.work_web.url delete 0 end
	.rolodex.form.internet.pagerpgp.pager delete 0 end
	.rolodex.form.internet.pagerpgp.pgp delete 0 end
	.rolodex.form.notes.misc.data delete 1.0 end
	.rolodex.form.notes.text delete 1.0 end
	.rolodex.form.spacer0.data configure -text ""
}

## add a record
proc db_add_record {} {
   global host result
   dp_RPC $host db_new_row   
   db_capture_record
   set result [dp_RPC $host db_put_row]
}

# not much changed for this one
proc db_get_name {} {
   global host current_type

   if {$current_type == "internet"} {
      set type EMAIL
      set field "internet.email.entry"
   } elseif {$current_type == "work"} {
      set type COMPANY 
      set field "work.name.entry"
   }   else {
      set type NAME; set field "personal.name.entry"
   }
	
   set seqlist [dp_RPC $host db_search_string $type [.rolodex.form.$field get]] 
   set seqno [lindex $seqlist 0]
   dp_RPC $host db_get_row $seqno
   db_display_record
}

## for each field value, if it has space(s), I need to replace them with "{}" before
## put them as args for RPC call
## on server side ,before save to database, there should be a reverse funtion.
## also for empty entry, send null string 
proc replace_space { value } {
# if any entry box is blank
  if { $value == "" } then {
    return "null"
  }
# if the text area is blank, you get a new line
  if { $value == "\n" } then {
    return "null"
  }

  regsub -all " " $value "{}" x
  return $x
} 

# function called when connect button is clicked
proc connect {} {
   global host server port
   if { [winfo exist .connect] == 0 } then { 
      toplevel .connect 
      wm title .connect "Remote Host:"

      frame .connect.f1
      pack .connect.f1 -fill x
      pack [entry .connect.f1.e1 -width 20 -textvariable server] -side right
      pack [label .connect.f1.l1 -text "Hostname: "] -side right

      pack [frame .connect.f3] -fill x
      pack [button .connect.f3.b1 -text Clear -command { .connect.f1.e1 delete 0 end} ] -side left
      pack [button .connect.f3.b2 -text "Connect" -command { 
		wm withdraw .connect 
		set host [dp_MakeRPCClient $server $port]
	 	if {![catch "dp_RPC $host db_open"]} {
			.rolodex.buttons.connect configure -foreground green
			.rolodex.buttons.connect configure -state disabled
			.rolodex.buttons.first invoke
			}
		 
		}] -side left
     
      return
   }
   wm deiconify .connect
}

proc disable_buttons {} {

	.rolodex.buttons.first configure -state disabled
	.rolodex.buttons.back configure -state disabled
	.rolodex.buttons.forward configure -state disabled
	.rolodex.buttons.last configure -state disabled
	.rolodex.buttons.sort configure -state disabled
	.rolodex.buttons.new_record configure -state disabled
	.rolodex.buttons.new_record_done configure -state disabled
	.rolodex.buttons.get_name configure -state disabled
	.rolodex.buttons.modify_record configure -state disabled
	.rolodex.buttons.delete_record configure -state disabled
	.rolodex.buttons.exit configure -state disabled

}

proc enable_buttons {} {

	.rolodex.buttons.first configure -state normal
	.rolodex.buttons.back configure -state normal
	.rolodex.buttons.forward configure -state normal
	.rolodex.buttons.last configure -state normal
	.rolodex.buttons.sort configure -state normal
	.rolodex.buttons.new_record configure -state normal
	.rolodex.buttons.new_record_done configure -state normal
	.rolodex.buttons.get_name configure -state normal
	.rolodex.buttons.modify_record configure -state normal
	.rolodex.buttons.delete_record configure -state normal
	.rolodex.buttons.exit configure -state normal

}