# cupsched - An event schedule program including budget events.
# Change year/month dialog.
# Rick Smereka, Copyright (C) 2008.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, get a copy via the Internet at
# http://gnu.org/copyleft/gpl.html or write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA

# You can contact the author via email at rsmereka@future-lab.com

# Orginal tcl version. Jul/2008, Rick Smereka

proc change_month {} {
   global yearmo_num month_num DBENG_LIST_DELIM DBENG_OK
   set dlg .cmdialog
   set mname "change_month"

   # check for already existing change year/month window
   if {[winfo exists $dlg] == 1} {
      focus $dlg.year
      return
   }

   if {[set ylist [get_year_db_list]] == ""} {
      return
   }

   # create change date dialog window
   toplevel $dlg
   wm protocol $dlg WM_DELETE_WINDOW "destroy $dlg"
   wm title $dlg "Change Month"
   label $dlg.lab_year -text "Year:" -anchor w

   # I cannot find a way to supply a list to 'tk_optionMenu'
   # so I am using 'eval'
   set stmt "tk_optionMenu $dlg.year year_num $ylist"
   eval $stmt

   grid config $dlg.lab_year -column 0 -row 0 \
      -sticky w -pady 8
   grid config $dlg.year -column 1 -row 0 \
      -sticky snew -pady 8
   label $dlg.lab_month -text "Month:" -anchor w
   tk_optionMenu $dlg.month month_num \
      01 02 03 04 05 06 07 08 09 10 11 12 
   grid config $dlg.lab_month -column 0 -row 1 \
      -sticky w -pady 8
   grid config $dlg.month -column 1 -row 1 \
      -sticky snew -pady 8
   set fr $dlg.buttons
   frame $fr -bd 0
   button $fr.ok -text "Ok" -command "change_date" -default active
   button $fr.cancel -text "Cancel" -command "destroy $dlg"
   pack $fr.ok -side top -fill x
   pack $fr.cancel -side top -fill x -pady 6
   grid config $fr -column 2 -row 0 -rowspan 4 \
      -padx 8 -pady 8
   bind $dlg <Key-Return> "check_date"
   bind $dlg <Key-Escape> "destroy $dlg"
   focus $dlg.year
}

proc change_date {} {
   global SCHED_FILTER_ALL
   set dlg .cmdialog

   set_title

   # close existing tables
   close_tables

   # re-open tables
   open_tables
   destroy $dlg

   # re-display events based on current year and month
   display_events $SCHED_FILTER_ALL
   focus .main.events
}


