"Fossies" - the Fresh Open Source Software Archive

Member "tkscanfax1/fax-pbook.tcl" (10 Feb 2005, 41607 Bytes) of package /linux/misc/old/tkscanfax-1.1.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Tcl/Tk source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # This file is a part of TkFax.
    2 #
    3 
    4 #
    5 # Phone book database has the following structure:
    6 # Each group has
    7 #   - group name
    8 #   - group description
    9 #   - list of group members
   10 # Each group member consists of
   11 #   - fax number
   12 #   - recipient
   13 #   - reference
   14 #   - description
   15 #
   16 # Phone book database is kept in two variables:
   17 #
   18 #   fax(grouplist)
   19 #     = { {group0|description0} {group0|description0} ... }
   20 #
   21 #   fax(group-groupname)
   22 #     = { {faxnumber0|recipient0|reference0|description0} ... }
   23 #
   24 # For delemeter(|), [TAB] will be used.
   25 #
   26 #---------------------------------------------------------------------
   27 
   28 proc fax_phonebook {} {
   29 #
   30 # Phone Book Window
   31 #
   32 # 10 Feb 2005 Masaki Shinomiya:  merge pbook
   33 # 19 Sep 2002 modified by R.Kawagishi
   34 #
   35     global fax m pbookwindow2 pbook_sort_order pbook_grpsort_order
   36     global pbook_modified_flag wn
   37 
   38     # Name of this window
   39 
   40     set wn $fax(mwn).pbook
   41     set fax(phonebookwin) $wn
   42     if [winfo exists $wn] {return}
   43     toplevel $wn
   44     wm title $wn "TkFax: Phone Book"
   45 
   46     # Top label
   47 
   48     frame $wn.0   -bd 10
   49     label $wn.0.l -text "TkFax: Phone  Book" -padx 20 -pady 4 -relief ridge
   50     pack  $wn.0.l -side top -fill x -expand yes
   51 
   52     # List of groups
   53 
   54     frame     $wn.g
   55     label     $wn.g.la -text "$m(group_select)"
   56     listbox   $wn.g.lb -height 8 -yscrollcommand "$wn.g.sy set" \
   57                        -width 10 -xscrollcommand "$wn.g.sx set"
   58     scrollbar $wn.g.sy -command "$wn.g.lb yview"
   59     scrollbar $wn.g.sx -command "$wn.g.lb xview" -orient horizontal
   60 
   61     grid $wn.g.la -row 1 -column 0 -rowspan 1 -columnspan 2 -sticky ew
   62     grid $wn.g.lb -row 3 -column 0 -rowspan 1 -columnspan 1 -sticky ewns
   63     grid $wn.g.sy -row 3 -column 1 -rowspan 1 -columnspan 1 -sticky ns
   64     grid $wn.g.sx -row 4 -column 0 -rowspan 1 -columnspan 1 -sticky ew
   65     grid rowconfigure    $wn.g 3 -weight 1
   66     grid columnconfigure $wn.g 0 -weight 1
   67 
   68     # spare space
   69 
   70     label $wn.x -text "" -pady 0
   71 
   72     # List of fax numbers
   73 
   74     frame $wn.l
   75     frame $wn.l.l
   76     label $wn.l.l.0 -text $m(group_name)  -width 16 -anchor w
   77     label $wn.l.l.1 -text $m(fax_number)  -width 16 -anchor w
   78     label $wn.l.l.2 -text $m(recipient)   -width 16 -anchor w -padx 4
   79     label $wn.l.l.3 -text $m(reference)   -width 16 -anchor w -padx 4
   80     label $wn.l.l.4 -text $m(description) -width 16 -anchor w -padx 4
   81     pack $wn.l.l.0 $wn.l.l.1 $wn.l.l.2 $wn.l.l.3 $wn.l.l.4 -side left -fill x
   82 
   83     text $wn.l.t -width 80 -height 10 -state disabled \
   84          -tabs {4c left 8c left 12c left 16c left} -wrap none \
   85          -xscroll "$wn.l.x set" -yscroll "$wn.l.y set" \
   86          -relief sunken -font $fax(f1)
   87     mscroll $wn.l.t
   88     scrollbar $wn.l.y -command "$wn.l.t yview"
   89     scrollbar $wn.l.x -command "$wn.l.t xview" -orient horizontal
   90 
   91     grid $wn.l.l  -row 0 -column 0 -rowspan 1 -columnspan 2 -sticky w
   92     grid $wn.l.t  -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news
   93     grid $wn.l.y  -row 1 -column 1 -rowspan 1 -columnspan 1 -sticky news
   94     grid $wn.l.x  -row 2 -column 0 -rowspan 1 -columnspan 1 -sticky news
   95     grid rowconfigure    $wn.l 1 -weight 1
   96     grid columnconfigure $wn.l 0 -weight 1
   97 
   98     # Group Entries
   99 
  100     frame $wn.j    -bd 2 -relief ridge
  101     label $wn.j.1  -text $m(group_name)  -anchor e -width 10
  102     label $wn.j.2  -text $m(description) -anchor e -width 10
  103     entry $wn.j.3  -textvariable fax(tmpgroupname) -width 20 \
  104                    -font $fax(f1) -fg $fax(c1)
  105     entry $wn.j.4  -textvariable fax(tmpgroupdescription) -width 40 \
  106                    -font $fax(f1) -fg $fax(c1)
  107     button $wn.j.a -text $m(clear) -width 6 -pady 0 -command {
  108                    fax_pbook_group_clear
  109     }
  110     button $wn.j.b -text $m(add)  -width 6 -pady 0 -command {
  111                    fax_pbook_group_add 
  112                    set pbook_modified_flag 1
  113     }
  114     button $wn.j.d -text $m(remove) -width 6 -pady 0 -command {
  115                    fax_pbook_group_remove 
  116     }
  117     button $wn.j.c -text $m(replace) -width 6 -pady 0 -command {
  118                    fax_pbook_group_replace
  119     }
  120     button $wn.j.e -text $m(sort) -width 6 -pady 0 -command {
  121                    fax_pbook_group_sort
  122     }
  123 
  124     grid $wn.j.1  -row 1 -column 1 -rowspan 1 -columnspan 1 -sticky news
  125     grid $wn.j.2  -row 2 -column 1 -rowspan 1 -columnspan 1 -sticky news
  126     grid $wn.j.3  -row 1 -column 2 -rowspan 1 -columnspan 2 -sticky news
  127     grid $wn.j.4  -row 2 -column 2 -rowspan 1 -columnspan 2 -sticky news
  128     grid $wn.j.a  -row 1 -column 4 -rowspan 1 -columnspan 1 -sticky news
  129     grid $wn.j.b  -row 1 -column 5 -rowspan 1 -columnspan 1 -sticky news
  130     grid $wn.j.c  -row 2 -column 5 -rowspan 1 -columnspan 1 -sticky news
  131     grid $wn.j.d  -row 1 -column 6 -rowspan 1 -columnspan 1 -sticky news
  132     grid $wn.j.e  -row 2 -column 6 -rowspan 1 -columnspan 1 -sticky news
  133     grid columnconfigure $wn.j 2 -weight 1
  134 
  135     # Fax Entries and Add and Edit buttons
  136 
  137     frame $wn.i   -bd 2 -relief ridge
  138     label $wn.i.1 -text $m(fax_number)  -anchor e -width 10
  139     label $wn.i.2 -text $m(recipient)   -anchor e -width 10
  140     label $wn.i.3 -text $m(reference)   -anchor e -width 10
  141     label $wn.i.4 -text $m(description) -anchor e -width 10
  142 
  143     entry $wn.i.5 -textvariable fax(tmpnumber) \
  144           -width 20 -font $fax(f1) -fg $fax(c1)
  145     entry $wn.i.6 -textvariable fax(tmprecipient) \
  146           -width 20 -font $fax(f1) -fg $fax(c1)
  147     entry $wn.i.7 -textvariable fax(tmpreference) \
  148           -width 20 -font $fax(f1) -fg $fax(c1)
  149     entry $wn.i.8 -textvariable fax(tmpdescription) \
  150           -width 20 -font $fax(f1) -fg $fax(c1)
  151 
  152     button $wn.i.a -text $m(clear)   -width 6 -pady 0 -command {
  153                    fax_pbook_faxnum_clear
  154     }
  155     button $wn.i.b -text $m(add)     -width 6 -pady 0 -command {
  156                    fax_pbook_faxnum_add
  157     } 
  158     button $wn.i.d -text $m(remove)  -width 6 -pady 0 -command {
  159                    fax_pbook_faxnum_remove
  160     }
  161     button $wn.i.c -text $m(replace) -width 6 -pady 0 -command {
  162                    fax_pbook_faxnum_replace
  163     }
  164 #    button $wn.i.e -text $m(sort)    -width 6 -pady 0 -command {
  165 #                   fax_pbook_faxnum_sort
  166 #    }
  167     menubutton $wn.i.e -text $m(sort) -width 6 -pady 0 -relief raised \
  168                        -menu $wn.i.e.sub -takefocus 1 -highlightthickness 2
  169 
  170     button $wn.i.f -text "$m(merge_phone_book) ..." -width 18 -pady 0 -command {
  171                    fax_pbook_merge_win $wn
  172     }
  173 
  174     grid $wn.i.1  -row 1 -column 1 -rowspan 1 -columnspan 1 -sticky news
  175     grid $wn.i.2  -row 2 -column 1 -rowspan 1 -columnspan 1 -sticky news
  176     grid $wn.i.3  -row 3 -column 1 -rowspan 1 -columnspan 1 -sticky news
  177     grid $wn.i.4  -row 4 -column 1 -rowspan 1 -columnspan 1 -sticky news
  178 
  179     grid $wn.i.5  -row 1 -column 2 -rowspan 1 -columnspan 2 -sticky news
  180     grid $wn.i.6  -row 2 -column 2 -rowspan 1 -columnspan 2 -sticky news
  181     grid $wn.i.7  -row 3 -column 2 -rowspan 1 -columnspan 2 -sticky news
  182     grid $wn.i.8  -row 4 -column 2 -rowspan 1 -columnspan 2 -sticky news
  183 
  184     grid $wn.i.a  -row 2 -column 4 -rowspan 1 -columnspan 1 -sticky news
  185     grid $wn.i.b  -row 2 -column 5 -rowspan 1 -columnspan 1 -sticky news
  186     grid $wn.i.c  -row 3 -column 5 -rowspan 1 -columnspan 1 -sticky news
  187     grid $wn.i.d  -row 2 -column 6 -rowspan 1 -columnspan 1 -sticky news
  188     grid $wn.i.e  -row 3 -column 6 -rowspan 1 -columnspan 1 -sticky news
  189     grid $wn.i.f  -row 4 -column 4 -rowspan 1 -columnspan 3 -sticky news
  190     grid columnconfigure $wn.i 2 -weight 1
  191 
  192     menu $wn.i.e.sub -tearoff no
  193     $wn.i.e.sub add command -label "$m(group)" -command {
  194                 fax_pbook_faxnum_sort 0
  195     }
  196     $wn.i.e.sub add command -label "$m(fax_number)" -command {
  197                 fax_pbook_faxnum_sort 2
  198     }
  199     $wn.i.e.sub add command -label "$m(recipient)" -command {
  200                 fax_pbook_faxnum_sort 3
  201     }
  202     $wn.i.e.sub add command -label "$m(reference)" -command {
  203                 fax_pbook_faxnum_sort 4
  204     }
  205     $wn.i.e.sub add command -label "$m(description)" -command {
  206                 fax_pbook_faxnum_sort 5
  207     }
  208 
  209     # SELECT / HELP / CANCEL / CLOSE Buttons
  210 
  211     frame  $wn.b   -bd 10
  212     button $wn.b.1 -text $m(use_this_number) -pady 2 -command {
  213            if { $fax(tmpnumber) == "" } {
  214                set q [tk_dialog $wn.dialog "TkFax Dialog" \
  215                    "$m(no_fax_number_selected)" {error} 0 $m(ok)]
  216            } else { 
  217                fax_pbook_save_faxnumberlist
  218                fax_pbook_select_faxnumber
  219                destroy $fax(phonebookwin)
  220            }
  221     }
  222     button $wn.b.4 -text $m(help) -command fax_pbook_help -pady 2
  223     #button $wn.b.5 -text "$m(help)(HTML)" -pady 2 \
  224     #               -command { fax_help_browse PhoneNumber_Help.html }
  225     button $wn.b.2 -text $m(cancel) -pady 2 -command {
  226     if {$pbook_modified_flag == 1} {
  227             fax_pbook_cancel
  228     } else {
  229             fax_pbook_close
  230         }
  231     }
  232     button $wn.b.3 -text $m(close)  -pady 2 \
  233                -command { fax_pbook_save_faxnumberlist
  234                               fax_pbook_close
  235                }
  236     pack $wn.b.3 $wn.b.2 $wn.b.4 $wn.b.1 \
  237          -side right -fill x -expand yes
  238 
  239     # Packing of all frames
  240 
  241     pack $wn.b $wn.i $wn.j -side bottom -fill x
  242     pack $wn.0             -side top    -fill x 
  243     pack $wn.g $wn.l       -side left   -fill both -expand yes
  244 
  245     # Set the globally accessed windows
  246 
  247     set fax(grouplistwin)  $wn.g.lb
  248     set fax(numberlistwin) $wn.l.t
  249     set fax(tmpnumwin)     $wn.i
  250 
  251     # Key and Mouse bindings
  252 
  253     bind $wn.i.5 <KeyPress-Return> {focus $fax(phonebookwin).i.6}
  254     bind $wn.i.6 <KeyPress-Return> {focus $fax(phonebookwin).i.7}
  255     bind $wn.i.7 <KeyPress-Return> {focus $fax(phonebookwin).i.8}
  256     bind $wn.i.8 <KeyPress-Return> fax_pbook_faxnum_add
  257     bind $wn.i.5 <KeyPress-Down>   {focus $fax(phonebookwin).i.6}
  258     bind $wn.i.6 <KeyPress-Down>   {focus $fax(phonebookwin).i.7}
  259     bind $wn.i.7 <KeyPress-Down>   {focus $fax(phonebookwin).i.8}
  260     bind $wn.i.6 <KeyPress-Up>     {focus $fax(phonebookwin).i.5}
  261     bind $wn.i.7 <KeyPress-Up>     {focus $fax(phonebookwin).i.6}
  262     bind $wn.i.8 <KeyPress-Up>     {focus $fax(phonebookwin).i.7}
  263     bind $wn.j.3 <KeyPress-Return> {focus $fax(phonebookwin).j.4}
  264     bind $wn.j.4 <KeyPress-Return>  fax_pbook_group_add
  265     bind $wn.j.3 <KeyPress-Down>   {focus $fax(phonebookwin).j.4}
  266     bind $wn.j.4 <KeyPress-Up>     {focus $fax(phonebookwin).j.3}
  267     bind $fax(numberlistwin) <Button-1> fax_pbook_faxnum_setcur
  268     bind $fax(numberlistwin) <Button-3> fax_pbook_faxnum_unsetcur
  269     set  pbookwindow2 [list $wn]
  270     bind $fax(numberlistwin) <Double-Button-1> {
  271                               fax_pbook_save_faxnumberlist
  272                               fax_pbook_select_faxnumber
  273                           wm withdraw $pbookwindow2  ;# hide window
  274     }
  275     bind $fax(grouplistwin)  <ButtonRelease-1> {fax_pbook_group_setcur %x %y}
  276     bind $fax(grouplistwin)  <Button-3>      fax_pbook_group_unsetcur
  277 #    bind $fax(grouplistwin)  <Double-Button> fax_pbook_select_group
  278 
  279     wm protocol $wn WM_DELETE_WINDOW {
  280         fax_pbook_save_faxnumberlist
  281         fax_pbook_close
  282     }
  283 
  284     # Initialization
  285 
  286     set fax(curgroupname)    "All"
  287     set fax(tmpgroupname)    "All"
  288     set fax(tmpgroupdescription) "Fax numbers from all groups"
  289     set fax(tmpnumber)           ""
  290     set fax(tmprecipient)        ""
  291     set fax(tmpreference)        ""
  292     set fax(tmpdescription)      ""
  293     set fax(group_and_number)    ""
  294 
  295     set pbook_sort_order(0) 0
  296     set pbook_sort_order(1) 0
  297     set pbook_sort_order(2) 0
  298     set pbook_sort_order(3) 0
  299     set pbook_sort_order(4) 0
  300     set pbook_sort_order(5) 0
  301     set pbook_grpsort_order 0
  302     set pbook_modified_flag 0
  303     set fax(removed_grouplist) {}
  304     set fax(group_selno)    0
  305 
  306     $fax(grouplistwin) selection set 0
  307     fax_pbook_display_grouplist
  308     $fax(grouplistwin) selection set 0
  309     fax_pbook_display_faxnumberlist All
  310 }
  311 
  312 #
  313 #  Merge pbook
  314 proc fax_pbook_merge_win {w} {
  315     global fax m
  316     # Name of this window
  317     set wm $fax(phonebookwin).merge
  318     if [winfo exists $wm] {return}
  319 
  320     toplevel $wm
  321     wm title $wm "TkFax: Merging Number Book"
  322 
  323     set oldpbook $fax(olduserdir)/pbook/group.pbd
  324 
  325     # Top label
  326 
  327     label $wm.l -text "Merging Phone Book:" -padx 20 -pady 4 -relief ridge
  328     frame $wm.1
  329     entry $wm.1.ent -width 32
  330     if [file exist $oldpbook] {
  331           $wm.1.ent insert  0 $oldpbook
  332     }
  333     button $wm.1.b -text "$m(select)..." -command {
  334     set pbook2 [tk_getOpenFile -defaultextension pbd \
  335          -filetypes { {"Phone book" .pbd} {"All files" *} } \
  336          -initialdir $fax(curdir) -initialfile group.pbd -parent $fax(phonebookwin).merge -title "Select Phone Book file"]
  337         if { "$pbook2" != "" } {
  338         $fax(phonebookwin).merge.1.ent delete 0 end
  339         $fax(phonebookwin).merge.1.ent insert  0 $pbook2
  340     }
  341     }
  342     pack  $wm.1.ent $wm.1.b -side left -fill x -expand yes
  343     frame $wm.2
  344     button $wm.2.b1 -text $m(excute)  -pady 2 \
  345        -command {fax_pbook_merge [$fax(phonebookwin).merge.1.ent get]
  346                  destroy $fax(phonebookwin).merge}
  347     button $wm.2.b2 -text $m(cancel) -pady 2 -command {destroy $fax(phonebookwin).merge}
  348     pack $wm.2.b2 $wm.2.b1 \
  349          -side right -fill x -expand yes
  350     pack $wm.l $wm.1 $wm.2 -side top -fill x -expand yes
  351 #fax_pbook_read_faxnumberlist
  352 }
  353 #
  354 # Procedures for phone book window
  355 #
  356 
  357 proc fax_pbook_read_faxnumberlist {} {
  358 #
  359 # This procedure reads group list file into the variable fax(grouplist).
  360 # Then it reads each group file into the variable fax(group-$groupname).
  361 #
  362 #  8 Feb 2005 Masaki Shinomiya: not use fax(pbookgroupfile)
  363 # 29 Sep 2002 modified by R.Kawagishi
  364 #
  365     global fax m
  366     global pbook_modified_flag
  367 
  368     # Read group list into a variable fax(grouplist).
  369     set groupfile  $fax(pbookdir)/group.pbd
  370     set fax(grouplist) {}
  371     if [file exist $groupfile] {
  372         set fid [open $groupfile r]
  373         while {[set line [gets $fid]]!={}} {
  374             lappend fax(grouplist) "$line"
  375         }
  376     }
  377 
  378     # Read fax number list into variables fax(group-$groupname)
  379 
  380     set fax(group_and_number) {}
  381     foreach group $fax(grouplist) {
  382         set groupname [lindex [split $group \t] 0]
  383         set groupdesc [list [lreplace $group 0 0]]
  384         set fax(group-$groupname) {}
  385         set file $fax(pbookdir)/$groupname.pbd
  386         if [file exist $file] {
  387             set fid [open $file r]
  388             while { [set line [gets $fid]] != {} } {
  389                 set work [split $line \t]
  390                 lappend fax(group-$groupname) $work
  391                 lappend fax(group_and_number) $groupname\t$groupdesc\t$work
  392             }
  393 
  394         } else {
  395             puts "TkFax: Fax list file $file $m(does_not_exist)"
  396         }
  397     }
  398     set fax(removed_grouplist) {}
  399     set pbook_modified_flag 0
  400 }
  401 
  402 #  9 Feb 2005  Masaki Shinomiya
  403 proc fax_pbook_merge { pbook2 } {
  404     global fax m
  405     global pbook_modified_flag
  406     set appendflag 0
  407     fax_debug "fax_pbook_merge is called with $pbook2."
  408     if [file isdirectory "$pbook2"] {
  409     set groupfile  $pbook2/group.pbd
  410     set pbookdir $pbook2
  411     } else {
  412     set groupfile $pbook2
  413     set pbookdir [file dirname $pbook2]
  414     }
  415     # Read group list into a variable fax(grouplist).
  416     if [file exist $groupfile] {
  417         set fid [open $groupfile r]
  418         while {[set line [gets $fid]]!={}} {
  419             set groupname [lindex [split $line \t] 0]
  420             set groupdesc [list [lreplace $line 0 0]]
  421             if { [lsearch $fax(grouplist) "${groupname}\t*"] < 0 } {
  422         fax_debug "$groupname is new group."
  423                 lappend fax(grouplist) "$line"
  424             set fax(group-$groupname) {}
  425         set appendflag 1
  426         } else {
  427         fax_debug "$groupname is already exists."
  428         }
  429 
  430         # Read fax number
  431         set file $pbookdir/$groupname.pbd
  432         if [file exist $file] {
  433             set fid2 [open $file r]
  434             while { [set line [gets $fid2]] != {} } {
  435                 set work [split $line \t]
  436         set number [lrange $work 0 1]
  437         if {[lsearch $fax(group-$groupname) "$number *" ] < 0 } {
  438             fax_debug "$work is new entry."
  439                 #puts "$groupname\t$groupdesc\t$work"
  440                 lappend fax(group-$groupname) $work
  441                 lappend fax(group_and_number) $groupname\t$groupdesc\t$work
  442         set appendflag 1
  443         } else {
  444             fax_debug "$work already exist."
  445         }
  446             }
  447         } else {
  448             fax_debug "TkFax: Fax number list file $file $m(does_not_exist)"
  449         }
  450 
  451         }
  452     }
  453     if $appendflag {
  454         $fax(grouplistwin) selection set 0
  455         fax_pbook_display_grouplist
  456         $fax(grouplistwin) selection set 0
  457         fax_pbook_display_faxnumberlist All
  458         set pbook_modified_flag 1
  459     }
  460     return $appendflag
  461 }
  462 proc fax_pbook_save_faxnumberlist {} {
  463 #
  464 # This saves fax number list stored in fax(group-groupname) into a file
  465 # $fax(pbookdir)/groupname.pbd, if changes are made.
  466 #
  467 # 12 Dec 2002 look up pbook_modified_flag (M.S)
  468 # 26 Sep 2002 modified by R.Kawagishi
  469 #
  470     global fax
  471     global pbook_modified_flag
  472 
  473     if { $pbook_modified_flag == 0 } { return }
  474 
  475     foreach groupname $fax(removed_grouplist) {
  476         set file "$fax(pbookdir)/$groupname.pbd"
  477     if [file exists $file] {
  478         file copy -force -- $file $file.bak
  479             file delete -- $file
  480     }
  481     }
  482     set fax(removed_grouplist) {}
  483 
  484     set gfile "$fax(pbookdir)/group.pbd"
  485     if [file exists $gfile] {
  486         file copy -force -- $gfile $gfile.bak
  487     }
  488     set gid [open $gfile w]
  489     foreach group $fax(grouplist) {
  490         puts $gid $group
  491         set groupname [lindex $group 0]
  492         set file "$fax(pbookdir)/$groupname.pbd"
  493     if [file exists $file] {
  494         file copy -force -- $file $file.bak
  495     }
  496         set fid [open $file w]
  497         foreach member $fax(group-$groupname) {
  498 #DEBUG        puts $fid $member
  499             set member2 [join $member \t]
  500             puts $fid $member2
  501         }
  502         close $fid
  503     }
  504     close $gid
  505 
  506     set pbook_modified_flag 0
  507 }
  508 
  509 proc fax_pbook_display_grouplist {} {
  510 #
  511 # This displays group list on $fax(grouplistwin),
  512 #
  513 # 14 Sep 2002 modified by R.Kawagishi
  514 #
  515     global fax
  516 
  517     $fax(grouplistwin) delete 0 end
  518     $fax(grouplistwin) insert end "All"
  519     foreach item $fax(grouplist) {
  520         set grpname [lindex $item 0]
  521         $fax(grouplistwin) insert end "$grpname"
  522     }
  523 }
  524 
  525 proc fax_pbook_group_setcur {x y} {
  526 #
  527 # This shows the group name and description selected by mouse.
  528 #
  529 # 19 Sep 2002 modified by R.Kawagishi
  530 #
  531     global fax
  532     global focused_grp_num focused_grp_name
  533 
  534     set elements [$fax(grouplistwin) get @$x,$y]
  535     set fax(curgroupname) [lindex $elements 0]
  536 
  537     set focused_grp_num  [$fax(grouplistwin) curselection]
  538     set focused_grp_name [$fax(grouplistwin) get $focused_grp_num]
  539 
  540     fax_pbook_display_group  [$fax(grouplistwin) curselection]
  541     fax_pbook_display_faxnumberlist $fax(tmpgroupname)
  542 }
  543 
  544 proc fax_pbook_group_unsetcur {} {
  545     global fax
  546 
  547 #    $fax(grouplistwin) tag delete cur
  548     $fax(grouplistwin) selection clear 0 end
  549     set fax(tmpgroupname) ""
  550     set fax(tmpgroupdescription) ""
  551 }
  552 
  553 proc fax_pbook_display_group { grp_selno } {
  554     global fax
  555 
  556     set fax(group_selno) $grp_selno
  557     if {$fax(group_selno) == 0} {
  558         set fax(curgroupname) "All"
  559         set fax(tmpgroupname) "All"
  560         set fax(tmpgroupdescription) "Fax numbers from all groups"
  561     } else {
  562         set grpdata [lindex $fax(grouplist) [expr $fax(group_selno) -1] ]
  563         set fax(curgroupname) [lindex $grpdata 0]
  564         set fax(tmpgroupname) [lindex $grpdata 0]
  565         set fax(tmpgroupdescription) [lreplace $grpdata 0 0]
  566     }
  567 }
  568 
  569 proc fax_pbook_group_clear {} {
  570     global fax
  571     fax_message ""
  572     set fax(tmpgroupname)    ""
  573     set fax(tmpgroupdescription) ""
  574     focus $fax(phonebookwin).j.3
  575 }
  576 
  577 proc fax_pbook_group_sort {} {
  578 #
  579 # 14 Sep 2002 create by R.Kawagishi
  580 #
  581     global fax pbook_grpsort_order
  582     global focused_grp_num focused_grp_name
  583 
  584     fax_message ""
  585 #    set focused_grp_num  [$fax(grouplistwin) curselection]
  586 #    set focused_grp_name [$fax(grouplistwin) get $focused_grp_num]
  587     if { $pbook_grpsort_order == 0 } {
  588         set fax(grouplist) [lsort -increasing -dictionary -index 0 $fax(grouplist)]
  589     } else {
  590         set fax(grouplist) [lsort -decreasing -dictionary -index 0 $fax(grouplist)]
  591     }
  592     set pbook_grpsort_order [expr ~$pbook_grpsort_order]
  593 
  594     $fax(grouplistwin) delete 0 end
  595     $fax(grouplistwin) insert end "All"
  596     set i 1
  597     foreach item $fax(grouplist) {
  598         set grpname [lindex $item 0]
  599         $fax(grouplistwin) insert end "$grpname"
  600         if {$grpname == $focused_grp_name} {
  601             set focused_grp_num $i
  602         }
  603         incr i
  604     }
  605     if {$grpname == "All"} {
  606         set focused_grp_num 0
  607     }
  608     $fax(grouplistwin) selection set $focused_grp_num
  609     $fax(grouplistwin) see $focused_grp_num
  610 }
  611 
  612 proc fax_pbook_groupname_check { groupname mode } {
  613     global fax m wn
  614     # mode: add|remove
  615     # check groupname to see it is non-empty or already used.
  616     if {$groupname==""} { return 1 }
  617     foreach reserved_group {All Misc} {
  618         if { $groupname == $reserved_group } {
  619             set q [tk_dialog $wn.dialog "TkFax Dialog" \
  620                   "$m(group) $reserved_group $m(is_reserved)"  {error} 0 $m(ok)]
  621             return 1
  622         }
  623     }
  624 
  625     set found 0
  626     foreach igroup $fax(grouplist) {
  627         set igroupname [lindex [split $igroup \t] 0]
  628         if {$groupname==$igroupname} {
  629         set found 1
  630         if {$mode == "add" } {
  631             set q [tk_dialog $wn.dialog "TkFax Dialog" \
  632                    "$m(group_name) $groupname $m(is_already_used)" \
  633                    {error} 0 $m(ok)]
  634             return 1
  635         } 
  636         }
  637     }
  638     if {$mode != "add" && $found == 0 } {
  639             set q [tk_dialog $wn.dialog "TkFax Dialog" \
  640                    "$m(group_name) $groupname $m(does_not_exist) " \
  641                    {error} 0 $m(ok)]
  642             return 1
  643     }
  644     return 0
  645 }
  646 
  647 proc fax_pbook_group_add {} {
  648 #
  649 # 14 Sep 2002 modified by R.Kawagishi
  650 #
  651     global fax m pbook_modified_flag wn
  652     global focused_grp_num focused_grp_name
  653 
  654     fax_message ""
  655     set fax(tmpgroupname) [string trim $fax(tmpgroupname)]
  656     set groupname $fax(tmpgroupname)
  657 #    set replace 0
  658     # check groupname to see it is non-empty or already used.
  659     if [fax_pbook_groupname_check $groupname add] {return 1}
  660 
  661     # Add a line to a list and create a new list variable.
  662 
  663     if {$fax(tmpgroupdescription) == ""} {
  664         set fax(tmpgroupdescription) "(none)"
  665     }
  666     set line "$groupname\t$fax(tmpgroupdescription)"
  667 #    $fax(grouplistwin) configure -state normal
  668     $fax(grouplistwin) insert end $groupname
  669     $fax(grouplistwin) yview end
  670 #    $fax(grouplistwin) configure -state disabled
  671     lappend fax(grouplist) $line
  672 #    lappend fax(group_and_number) $line
  673     set fax(group-$groupname) {}
  674 
  675     # Check whether database file already exists. If so, try to read it in.
  676 
  677     set file $fax(pbookdir)/$groupname.pbd
  678     if [file exist $file] {
  679         set q [tk_dialog $wn.dialog "TkFax Dialog" \
  680   "$m(phone_book_database_file) $file $m(is_already_exists) $m(do_you_want_to_read_it_in)" \
  681                {question} 0 $m(yes) $m(no) ]
  682         if {$q==0} {
  683             set fid [open $file r]
  684             while {[set line [gets $fid]]!={}} {
  685                 lappend fax(group-$groupname) "$line"
  686             }
  687         }
  688     }
  689 
  690     #set m(is_added) "is added"
  691 
  692     fax_pbook_display_grouplist
  693     set grp_lb_no [llength $fax(grouplist)]
  694     set fax(group_selno)    $grp_lb_no
  695     fax_pbook_display_group $grp_lb_no
  696     $fax(grouplistwin) selection set $grp_lb_no
  697     $fax(grouplistwin) see $grp_lb_no
  698     set focused_grp_num  $grp_lb_no
  699     set focused_grp_name $groupname
  700     fax_pbook_display_faxnumberlist $groupname
  701     fax_message "Phone book: $m(group_name) '$groupname' $m(is_added)"
  702     set pbook_modified_flag 1
  703 
  704     # Ready for another addition.
  705 
  706     focus $fax(phonebookwin).j.3
  707 }
  708 
  709 proc fax_pbook_group_remove {} {
  710 # 
  711 # 26 Sep 2001 modified by Masaki Shinomiya
  712 # 14 Sep 2002 modified by R.Kawagishi
  713 #
  714     global fax m pbook_modified_flag wn
  715     global focused_grp_num focused_grp_name
  716 
  717     fax_message ""
  718     set fax(tmpgroupname) [string trim $fax(tmpgroupname)]
  719     set groupname $fax(tmpgroupname)
  720 
  721     # check groupname to see it is non-empty or reserved.
  722     if [fax_pbook_groupname_check $groupname remove] {return 1}
  723     set file $fax(pbookdir)/$groupname.pbd
  724     set q [tk_dialog $wn.dialog "TkFax Dialog" \
  725            "$m(to_delete_group) '$groupname' - $m(is_it_ok)"\
  726            {question} 1 $m(yes) $m(no) ]
  727     if {$q==0} {
  728         set i 0
  729         foreach groupdata $fax(grouplist) {
  730             incr i
  731             if {[lindex $groupdata 0] == $groupname} {
  732                 set grp_no $i
  733             }
  734         }
  735         set glist_no [expr $grp_no -1]
  736     set new_glist [lreplace $fax(grouplist) $glist_no $glist_no]
  737     set fax(grouplist) $new_glist
  738     fax_pbook_display_grouplist
  739 
  740         set fax(group_selno) 0
  741         $fax(grouplistwin) selection set 0
  742         set focused_grp_num  0
  743         set focused_grp_name "All"
  744 
  745     fax_pbook_display_faxnumberlist All
  746         set fax(tmpgroupname) ""
  747         set fax(tmpgroupdescription) ""
  748         unset fax(group-$groupname)
  749         # exec rm -f $file
  750     lappend fax(removed_grouplist) $groupname
  751         fax_message \
  752             "Phone book: $m(group) '$groupname' $m(deleted)"
  753         set pbook_modified_flag 1
  754     }
  755 }
  756 
  757 proc fax_pbook_group_replace {} {
  758 #
  759 # 14 Sep 2002 creat by R.Kawagishi
  760 #
  761     global fax m pbook_modified_flag wn
  762     global focused_grp_num focused_grp_name
  763 
  764     fax_message ""
  765     set grp_name     $fax(curgroupname)
  766     set fax(tmpgroupname) [string trim $fax(tmpgroupname)]
  767     set new_grp_name $fax(tmpgroupname)
  768 
  769     #if { $new_grp_name == "" } { return 1}
  770     # check groupname to see it is non-empty or reserved.
  771     if [fax_pbook_groupname_check $grp_name remove] {return 1}
  772     if {$new_grp_name != $grp_name} {
  773       # check groupname to see it is non-empty or already used.
  774       if [fax_pbook_groupname_check $new_grp_name add] {return 1}
  775     }
  776 
  777 #    set grp_lb_no [$fax(grouplistwin) curselection]
  778     set grp_lb_no $focused_grp_num
  779     if { [llength $grp_lb_no] != 1 } {
  780     fax_debug "grouplistwin curselection = $grp_lb_no"
  781         set q [tk_dialog $wn.dialog "TkFax Dialog" \
  782             "$m(select_group_other_than_all)"  {error} 0 $m(ok)]
  783     return 1
  784     }
  785     set glist_no  [expr $grp_lb_no -1]
  786     set grp_desc  [lindex [lindex $fax(grouplist) $glist_no] 1]
  787 
  788     set q [tk_dialog $wn.dialog "TkFax Dialog" \
  789 "$m(group_name)íž$grp_name
  790 $m(description)íž$grp_desc
  791 -->
  792 $m(group_name)íž$new_grp_name
  793 $m(description)íž$fax(tmpgroupdescription)
  794 $m(confirm_change)" \
  795     {question} 0 $m(ok) $m(cancel)]
  796     if {$q == 0} {
  797         set grp_dat   "$new_grp_name\t$fax(tmpgroupdescription)"
  798         set new_glist [lreplace $fax(grouplist) $glist_no $glist_no $grp_dat]
  799         set fax(grouplist) $new_glist
  800         set fax(group-$new_grp_name) $fax(group-$grp_name)
  801         if {$new_grp_name != $grp_name} {
  802             unset fax(group-$grp_name)
  803         lappend fax(removed_grouplist) $grp_name
  804         }
  805         set fax(tmpgroupname) ""
  806         set fax(tmpgroupdescription) ""
  807         $fax(grouplistwin) delete 0 end
  808         $fax(grouplistwin) insert end "All"
  809         foreach item $fax(grouplist) {
  810             $fax(grouplistwin) insert end [lindex $item 0]
  811         }
  812     fax_pbook_display_grouplist
  813         set fax(group_selno)    $grp_lb_no
  814         fax_pbook_display_group $grp_lb_no
  815         $fax(grouplistwin) selection set $grp_lb_no
  816         $fax(grouplistwin) see $grp_lb_no
  817     fax_pbook_display_faxnumberlist $new_grp_name
  818         fax_message "Phone book: $m(group_name) $new_grp_name $m(is_updated)"
  819         set pbook_modified_flag 1
  820     }
  821 }
  822 
  823 proc fax_pbook_select_group {} {
  824 #
  825 # This select a group for faxing.
  826 #
  827     global fax
  828     set fax(number)      group:$fax(tmpgroupname)
  829     set fax(recipient)   $fax(tmpgroupdescription)
  830     destroy $fax(phonebookwin)
  831 }
  832 
  833 proc fax_pbook_display_faxnumberlist { groupname } {
  834 #
  835 # This displays fax number list of a selected group on $fax(numberlistwin).
  836 #
  837 # 19 Sep 2002 modified by R.Kawagishi
  838 #
  839     global fax pbook_sort_order
  840 
  841     $fax(numberlistwin) configure -state normal
  842     $fax(numberlistwin) delete 1.0 end
  843     set fax(group_and_number) ""
  844 
  845     if { $groupname == "All" } {
  846         set fax(group-All) {}
  847         foreach group $fax(grouplist) {
  848             set groupname [lindex $group 0]
  849             set groupdesc [list [lreplace $group 0 0]]
  850             foreach member $fax(group-$groupname) {
  851                 lappend fax(group-All) "$groupname\t[join $member \t]"
  852                 lappend fax(group_and_number) $groupname\t$groupdesc\t[join $member \t]
  853             }
  854         }
  855 
  856 #        if { $pbook_sort_order == 0 } {
  857 #            set fax(group-All) \
  858 #            [lsort -increasing -command fax_recipient_compare $fax(group-All)]
  859 #        } else {
  860 #            set fax(group-All) \
  861 #            [lsort -decreasing -command fax_recipient_compare $fax(group-All)]
  862 #        }
  863         foreach member $fax(group-All) {
  864             $fax(numberlistwin) insert end "$member\n"
  865         }
  866     } else {
  867         set groupdesc [list $fax(tmpgroupdescription)]
  868         foreach member $fax(group-$groupname) {
  869             $fax(numberlistwin) insert end "$groupname\t[join $member \t]\n"
  870             lappend fax(group_and_number) "$groupname\t$groupdesc\t[join $member \t]"
  871         }
  872     }
  873     $fax(numberlistwin) delete {end -1 char}
  874     $fax(numberlistwin) configure -state disabled
  875 }
  876 
  877 proc fax_pbook_faxnum_setcur {} {
  878 #
  879 # This displays faxnumber element on entry windows when left mouse button is
  880 # pressed on $fax(numberlistwin) and deselect it when right mouse button is
  881 # pressed.
  882 #
  883 # 14 Sep 2002 modified by R.Kawagishi
  884 #
  885     global fax
  886 
  887     $fax(numberlistwin) tag delete cur
  888     $fax(numberlistwin) tag configure cur -foreground red -background skyblue
  889     $fax(numberlistwin) tag add cur \
  890                                 {current linestart} {current lineend +1 char}
  891     set line [$fax(numberlistwin) get {current linestart} {current lineend}]
  892     set elements [split $line \t]
  893 
  894     if {$fax(group_selno) > 0} {
  895         set grpdata [lindex $fax(grouplist) [expr $fax(group_selno) -1] ]
  896         set fax(curgroupname) [lindex $grpdata 0]
  897         set fax(tmpgroupname) [lindex $grpdata 0]
  898 #        set fax(tmpgroupdescription) [lindex $grpdata 1]
  899         set fax(tmpgroupdescription) [lreplace $grpdata 0 0]
  900     } else {
  901         set fax(curgroupname) [lindex $elements 0]
  902         set fax(tmpgroupname) [lindex $elements 0]
  903         regexp {^.} [$fax(numberlistwin) index current] line_number
  904         set work [lindex $fax(group_and_number) [expr $line_number -1] ]
  905         set fax(tmpgroupdescription) [lindex $work 1]
  906     }
  907     set fax(tmpnumber)      [lindex $elements 1]
  908     set fax(tmprecipient)   [lindex $elements 2]
  909     set fax(tmpreference)   [lindex $elements 3]
  910     set fax(tmpdescription) [lindex $elements 4]
  911 }
  912 
  913 proc fax_pbook_faxnum_unsetcur {} {
  914     global fax
  915     $fax(numberlistwin) tag delete cur
  916     set fax(tmpnumber)      ""
  917     set fax(tmprecipient)   ""
  918     set fax(tmpreference)   ""
  919     set fax(tmpdescription) ""
  920 }
  921 
  922 #
  923 # These two procedures sort the faxnumberlist.
  924 
  925 proc fax_pbook_faxnum_sort {item} {
  926     global fax pbook_sort_order
  927 
  928     fax_message ""
  929     set newlist1 ""
  930     foreach line $fax(group_and_number) {
  931         set orglist  [split $line \t]
  932         set work2    [lindex $orglist 2]
  933         set sho_num  [num_shorten $work2]
  934         set new_line [lappend orglist $work2]
  935         set new_line [lreplace $new_line 2 2 $sho_num]
  936         lappend newlist1 $new_line
  937     }
  938 
  939     if { $pbook_sort_order($item) == 0 } {
  940         set newlist2 \
  941         [lsort -increasing -dictionary -index $item $newlist1]
  942     } else {
  943         set newlist2 \
  944         [lsort -decreasing -dictionary -index $item $newlist1]
  945     }
  946     set pbook_sort_order($item) [expr ~$pbook_sort_order($item)]
  947 
  948     set fax(group_and_number) ""
  949     foreach line $newlist2 {
  950         set new_line [lreplace $line 2 2 [lindex $line 6]]
  951         set new_line [lreplace $new_line 6 6]
  952         lappend fax(group_and_number) $new_line
  953     }
  954 
  955     $fax(numberlistwin) configure -state normal
  956     $fax(numberlistwin) delete 1.0 end
  957     set newlist ""
  958 
  959     foreach line $fax(group_and_number) {
  960         $fax(numberlistwin) insert end [lindex $line 0]\t
  961         $fax(numberlistwin) insert end [lindex $line 2]\t
  962         $fax(numberlistwin) insert end [lindex $line 3]\t
  963         $fax(numberlistwin) insert end [lindex $line 4]\t
  964         $fax(numberlistwin) insert end [lindex $line 5]\n
  965         lappend newlist [lindex $line 0]\t[lindex $line 1]\t[lindex $line 2]\t[lindex $line 3]\t[lindex $line 4]\t[lindex $line 5]
  966     }
  967     set fax(group_and_number) $newlist
  968     $fax(numberlistwin) configure -state disabled
  969 }
  970 
  971 #proc fax_recipient_compare { a b } {
  972 #    set x [lindex [split $a \t] 1]
  973 #    set y [lindex [split $b \t] 1]
  974 #    return [string compare $x $y]
  975 #}
  976 
  977 proc fax_pbook_faxnum_clear {} {
  978 #
  979 # This clears entry windows.
  980 #
  981     global fax
  982     set fax(tmpnumber)      ""
  983     set fax(tmprpbook_modified_flagecipient)   ""
  984     set fax(tmprecipient)   ""
  985     set fax(tmpreference)   ""
  986     set fax(tmpdescription) ""
  987     focus $fax(phonebookwin).i.5
  988 }
  989 
  990 proc fax_pbook_faxnum_check { faxnumber } {
  991     global fax m
  992 
  993     set number [string trim $faxnumber]
  994     if { $number == {} } {
  995         tk_messageBox -message $m(enter_fax_number) -icon error -type ok
  996         return 1
  997     }
  998 
  999     if { [num_shorten $number] == "-" } {
 1000         tk_messageBox -message "$m(fax_number_illegal):\n$number" -icon error -type ok
 1001         return 1
 1002     }
 1003 
 1004     return 0
 1005 }
 1006 
 1007 proc fax_pbook_faxnum_add {} {
 1008 #
 1009 # This adds a new fax number to the current group.
 1010 #
 1011 # 12 Dec 2002 set pbook_modified_flag (M.S)
 1012 # 16 Sep 2002 modified by R.Kawagishi
 1013 #
 1014     global fax m
 1015     global pbook_modified_flag wn
 1016 
 1017     fax_message ""
 1018     set fax(tmpnumber) [string trim $fax(tmpnumber)]
 1019     if [fax_pbook_faxnum_check $fax(tmpnumber)] {return 1}
 1020     set groupname $fax(curgroupname)
 1021     set grp_lb_no [$fax(grouplistwin) curselection]
 1022     if { [llength $grp_lb_no] != 1 } {
 1023     fax_debug "grouplistwin curselection = $grp_lb_no"
 1024         set q [tk_dialog $wn.dialog "TkFax Dialog" \
 1025             "$m(select_group_other_than_all)"  {error} 0 $m(ok)]
 1026     return 1
 1027     }
 1028     set glist_no  [expr $grp_lb_no -1]
 1029     set grp_desc  [lindex [lindex $fax(grouplist) $glist_no] 1]
 1030     if {$groupname== "All"} {
 1031         set groupname "Misc"
 1032     set grp_desc  [list "Miscellaneous fax numbers"]
 1033     }
 1034 
 1035     if {$fax(tmprecipient)   == ""} {set fax(tmprecipient)   "(none)"}
 1036     if {$fax(tmpreference)   == ""} {set fax(tmpreference)   "(none)"}
 1037     if {$fax(tmpdescription) == ""} {set fax(tmpdescription) "(none)"}
 1038 
 1039     $fax(numberlistwin) configure -state normal
 1040     set line1 "$fax(tmpnumber)\t$fax(tmprecipient)\t$fax(tmpreference)\t$fax(tmpdescription)"
 1041     set line2 [list $fax(tmpnumber) $fax(tmprecipient) $fax(tmpreference) $fax(tmpdescription)]
 1042 
 1043     set insertpoint [$fax(numberlistwin) index end]
 1044     $fax(numberlistwin) insert end "\n$groupname\t$line1"
 1045 
 1046     if {[$fax(numberlistwin) get 1.0]=="\n"} {
 1047         $fax(numberlistwin) delete 1.0
 1048     }
 1049     $fax(numberlistwin) yview end
 1050     $fax(numberlistwin) configure -state disabled
 1051     lappend fax(group-$groupname) $line2
 1052     lappend fax(group_and_number) $groupname\t$grp_desc\t$line1
 1053 
 1054     fax_message \
 1055         "Phone book: $m(fax_number) '$fax(tmpnumber)' $m(is_registered_in) $groupname group."
 1056     fax_pbook_faxnum_clear
 1057     focus $fax(phonebookwin).i.5
 1058     set pbook_modified_flag 1
 1059 }
 1060 
 1061 proc fax_pbook_faxnum_remove {} {
 1062 #
 1063 # This removes a fax number from the current group.
 1064 #
 1065 # 12 Dec 2002 faxnum_remove_search, pbook_modified_flag (M.S)
 1066 # 26 Sep 2001 error trap when no nummbers selected
 1067 # 14 Sep 2002 modified by R.Kawagishi
 1068 #
 1069     global fax m
 1070     global pbook_modified_flag wn
 1071 
 1072     fax_message ""
 1073     set fax(tmpnumber) [string trim $fax(tmpnumber)]
 1074     if { $fax(tmpnumber) ==  "" } { return 1 }
 1075     set groupname $fax(curgroupname)
 1076     if {$groupname == "All" || $groupname == ""} {
 1077         set q [tk_dialog $wn.dialog "TkFax Dialog" \
 1078             "$m(select_group_other_than_all)"  {error} 0 $m(ok)]
 1079         return
 1080         #set work3 [lreplace $fax(group_and_number) $line_num $line_num]
 1081         #set fax(group_and_number) $work3
 1082     }
 1083     if { [$fax(numberlistwin) tag nextrange cur 1.0 end] == "" } {
 1084         set q [tk_dialog $wn.dialog "TkFax Dialog" \
 1085             "$m(select_fax_number)"  {error} 0 $m(ok)]
 1086         return
 1087     }
 1088     set q [tk_dialog $wn.dialog "TkFax Dialog" \
 1089           "$m(to_delete_fax_number) $fax(tmpnumber) $m(is_it_ok)"\
 1090            {question} 1 $m(yes) $m(no) ]
 1091     if {$q==0} {
 1092 
 1093         regexp {^.} [$fax(numberlistwin) index cur.first] work1
 1094     set line_num1 [expr $work1 -1]
 1095         set line_num2 [faxnum_remove_search $line_num1]
 1096         set work [lreplace $fax(group_and_number) $line_num1 $line_num1]
 1097         set fax(group_and_number) $work
 1098         set work [lreplace $fax(group-$fax(curgroupname)) $line_num2 $line_num2]
 1099         set fax(group-$fax(curgroupname)) $work
 1100         $fax(numberlistwin) configure -state normal
 1101         $fax(numberlistwin) delete cur.first cur.last
 1102         $fax(numberlistwin) configure -state disabled
 1103         fax_message \
 1104             "Phone book: '$fax(tmpnumber)'  in $m(group) '$groupname' $m(is_deleted)"
 1105     foreach i {number recipient reference description} {
 1106         set fax(tmp$i) ""
 1107     }
 1108         set pbook_modified_flag 1
 1109     }
 1110 }
 1111 
 1112 proc faxnum_remove_search { line_num } {
 1113     # 12 Dec 2002  (M.S)
 1114     global fax
 1115         set work2 [split [lindex $fax(group_and_number) $line_num] \t]
 1116     set work4 [lreplace $work2 0 1]
 1117         set work5 [lsearch $fax(group-$fax(curgroupname)) $work4]
 1118 #DEBUG  puts "$fax(curgroupname) $work5"
 1119     return $work5
 1120 }
 1121 
 1122 proc fax_pbook_faxnum_replace {} {
 1123 #
 1124 # This replaces the selected faxnumber with corrected info.
 1125 #
 1126 # 12 Dec 2002 use faxnum_remove_search, set pbook_modified_flag (M.S)
 1127 # 26 Sep 2001 error trap when no nummbers selected
 1128 # 20 Sep 2001 check the group, replacing only one item
 1129 # 19 Sep 2002 modified by R.Kawagishi
 1130 
 1131     global fax m
 1132     global pbook_modified_flag wn
 1133 
 1134     fax_message ""
 1135     set fax(tmpnumber) [string trim $fax(tmpnumber)]
 1136     if [fax_pbook_faxnum_check $fax(tmpnumber)] {return 1}
 1137     set groupname $fax(curgroupname)
 1138     if {$groupname == "All" || $groupname == ""} {
 1139             set q [tk_dialog $wn.dialog "TkFax Dialog" \
 1140                   "$m(select_group_other_than_all)"  {error} 0 $m(ok)]
 1141         return
 1142     }
 1143     if { [$fax(numberlistwin) tag nextrange cur 1.0 end] == "" } {
 1144         set q [tk_dialog $wn.dialog "TkFax Dialog" \
 1145             "$m(select_fax_number)"  {error} 0 $m(ok)]
 1146         return
 1147     }
 1148 
 1149 #    set glist_no [$fax(grouplistwin) curselection]
 1150 #    set grp_desc [list [lreplace [lindex $fax(grouplist) $glist_no] 0 0]]
 1151 
 1152     set grp_desc [list [lreplace [lindex $fax(grouplist) $fax(group_selno)] 0 0]]
 1153 
 1154     if {$groupname== "All"} {
 1155         set groupname "Misc"
 1156         set grp_desc  [list "Miscellaneous fax numbers"]
 1157     }
 1158     if {$fax(tmprecipient)   == ""} {set fax(tmprecipient)   "(none)"}
 1159     if {$fax(tmpreference)   == ""} {set fax(tmpreference)   "(none)"}
 1160     if {$fax(tmpdescription) == ""} {set fax(tmpdescription) "(none)"}
 1161 
 1162     regexp {^.} [$fax(numberlistwin) index cur.first] work
 1163     set line_num1 [expr $work -1]
 1164     set line_num2 [faxnum_remove_search $line_num1]
 1165     $fax(numberlistwin) configure -state normal
 1166     set insertpoint [$fax(numberlistwin) index cur.first]
 1167     set endpoint    [$fax(numberlistwin) index end]
 1168 
 1169     $fax(numberlistwin) delete cur.first cur.last
 1170     set line1 \
 1171     "$fax(tmpnumber)\t$fax(tmprecipient)\t$fax(tmpreference)\t$fax(tmpdescription)"
 1172     set line2 [list \
 1173         $fax(tmpnumber) $fax(tmprecipient) $fax(tmpreference) $fax(tmpdescription)]
 1174 
 1175     if { $insertpoint < [expr $endpoint-1] } {
 1176         $fax(numberlistwin) insert $insertpoint "$groupname\t$line1\n"
 1177     } elseif { $insertpoint > 1 } {
 1178         $fax(numberlistwin) insert $insertpoint "\n$groupname\t$line1"
 1179     } else {
 1180         $fax(numberlistwin) insert $insertpoint "$groupname\t$line1"
 1181     }
 1182     $fax(numberlistwin) configure -state disabled
 1183 #    fax_pbook_reset_numberlist
 1184     set work [lreplace $fax(group-$fax(curgroupname)) $line_num2 $line_num2 $line2]
 1185     set fax(group-$fax(curgroupname)) $work
 1186 
 1187     set work [lreplace $fax(group_and_number) $line_num1 $line_num1 \
 1188               $groupname\t$grp_desc\t$line1]
 1189     set fax(group_and_number) $work
 1190     set pbook_modified_flag 1
 1191 }
 1192 
 1193 proc fax_pbook_select_faxnumber {} {
 1194 #
 1195 # This selects current faxnumber for faxing.
 1196 #
 1197     global fax m wn
 1198 
 1199     fax_message ""
 1200     set fax(tmpnumber) [string trim $fax(tmpnumber)]
 1201     if [fax_pbook_faxnum_check $fax(tmpnumber)] {return 1}
 1202     set fax(number)      $fax(tmpnumber)
 1203     set fax(recipient)   $fax(tmprecipient)
 1204     set fax(reference)   $fax(tmpreference)
 1205     set fax(description) $fax(tmpdescription)
 1206 #    destroy $fax(phonebookwin)
 1207 }
 1208 
 1209 proc fax_pbook_cancel {} {
 1210 #
 1211 # 29 Sep 2001
 1212 
 1213     global m wn
 1214 
 1215     fax_message ""
 1216     set q [tk_dialog $wn.dialog "TkFax Dialog" \
 1217            "$m(abort_all_changes_and_exit) $m(is_it_ok)"\
 1218            {question} 0 $m(yes) $m(no) ]
 1219     if {$q==0} {
 1220         fax_pbook_read_faxnumberlist
 1221         fax_pbook_close
 1222     fax_message ""
 1223     }
 1224 }
 1225 
 1226 proc fax_pbook_close {} {
 1227 #
 1228 # This closes the phone book window.
 1229 #
 1230     global fax
 1231     fax_message ""
 1232 #   fax_pbook_save_faxnumberlist
 1233    destroy $fax(phonebookwin)
 1234 }
 1235 
 1236 proc fax_pbook_help {} {
 1237     global fax m
 1238     fax_help "Phone Book Help" "$m(pbookhlp)"
 1239 }
 1240