# NEED #
# Check for failure on all database queries

#!/usr/bin/perl -w
#
# This is an example of a subclass of the generated application
#
# You can safely edit this file, any changes that you make will be preserved
# and this file will not be overwritten by the next run of Glade::PerlGenerate
#
#==============================================================================
#=== This is the 'Subshipping_window' class                              
#==============================================================================
package Subshipping_window;
require 5.000; use strict 'vars', 'refs', 'subs';
# UI class 'Subshipping_window' (version 0.01)
# 
# Copyright (c) Date Thu Aug 22 12:40:43 CDT 2002
# Author Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
# Unspecified copying policy, please contact the author\n#  Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
#==============================================================================
# This perl source file was automatically generated by 
# Glade::PerlGenerate version 0.56 - Wed Apr 19 02:28:58 BST 2000
# Copyright (c) Author Dermot Musgrove <dermot.musgrove\@virgin.net>
#
# from Glade file /afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/ccdb.glade
# Thu Aug 22 12:40:43 CDT 2002
#==============================================================================

BEGIN {
    use vars qw( 
                 @ISA
                 %fields
                 $VERSION
             );
    # Existing signal handler modules
    use src::CCDB;
    # We need the Gnome bindings as well
    use Gnome;
    # Uncomment the line below to enable gettext checking
#    use Glade::PerlSource;
    # Tell interpreter who we are inheriting from
    @ISA     = qw( shipping_window );
    # Uncomment the line below to enable gettext checking
#    @ISA      = qw( shipping_window Glade::PerlSource );
    $VERSION = '0.01';
    # Inherit the AUTOLOAD dynamic methods from shipping_window
    *AUTOLOAD = \&shipping_window::AUTOLOAD;
} # End of sub BEGIN

%fields = (
# Insert any extra data access methods that you want to add to 
#   our inherited super-constructor (or overload)
    USERDATA    => undef,
    VERSION     => '0.01',
);

sub DESTROY {
    # This sub will be called on object destruction
} # End of sub DESTROY

#==============================================================================
#=== Below are the overloaded class constructors
#==============================================================================
sub new {
    my $that  = shift;
    # Allow indirect constructor so that we can call eg. 
    #   $window1 = BusFrame->new; $window2 = $window1->new;
    my $class = ref($that) || $that;

    # Call our super-class constructor to get an object and reconsecrate it
    my $self = bless $that->SUPER::new(), $class;

    # Add our own data access methods to the inherited constructor
    my($element);
    foreach $element (keys %fields) {
        $self->{_permitted_fields}->{$element} = $fields{$element};
    }
    @{$self}{keys %fields} = values %fields;
    return $self;
} # End of sub new

sub run {
    my ($class, $type, $cost) = @_;
    return unless Gtk->main_level == 1;
    Gnome->init('CCDB', '0.01');
    # Uncomment the line below to enable gettext checking
#    $class->check_gettext_strings;
    my $window = $class->new;
    # Insert your subclass user data key/value pairs 
    $window->USERDATA({
#        'Key1'   => 'Value1',
#        'Key2'   => 'Value2',
#        'Key3'   => 'Value3',
    });
    $window->TOPLEVEL->show;
#    my $window2 = $window->new;
#    $window2->TOPLEVEL->show;

    $window->{FORM}{type}->set_text($type);
    $window->{FORM}{cost}->set_text($cost);

    Gtk->main;
    # Uncomment the line below to enable gettext checking
#    $window->write_gettext_strings("__", '/afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/src/CCDB.pot');
    my $type = $window->{FORM}{type}->get_text;
    (my $cost = $window->{FORM}{cost}->get_text) =~ s/\$//;
    $window->{FORM}{shipping_window}->destroy;
    return ($type, $cost);
} # End of sub run
#===============================================================================
#=== Below are (overloaded) default signal handlers for 'shipping_window' class 
#===============================================================================
sub about_Form {
    my ($class) = @_;
    my $gtkversion = 
        Gtk->major_version.".".
        Gtk->minor_version.".".
        Gtk->micro_version;
    my $name = $0;
    #
    # Create a Gnome::About '$ab'
    my $ab = new Gnome::About(
        "SubCCDB", 
        "0.01", 
        _("Copyright")." Thu Aug 22 12:40:43 CDT 2002", 
        "Nathan Mueller <nmueller\@newton.cs.wisc.edu>", 
        _("No description")."\n".
        "Gtk ".     _("version").": $gtkversion\n".
        "Gtk-Perl "._("version").": $Gtk::VERSION\n".
        _("run from file").": $name\n".
        "# Unspecified copying policy, please contact the author\n# ", 
        "$Glade::PerlRun::pixmaps_directory/glade2perl_logo.xpm", 
    );
    $ab->set_title(_("About")." SubCCDB" );
    $ab->position('mouse' );
    $ab->set_policy(1, 1, 0 );
    $ab->set_modal(1 );
    $ab->show;
} # End of sub about_Form

sub destroy_Form {
    my ($class, $data, $object, $instance) = @_;
    Gtk->main_quit; 
} # End of sub destroy_Form

sub toplevel_hide    { shift->get_toplevel->hide    }
sub toplevel_close   { shift->get_toplevel->close   }
sub toplevel_destroy { shift->get_toplevel->destroy }


#==============================================================================
#=== Below are (overloaded) signal handlers for 'shipping_window' class 
#==============================================================================
sub on_cancel_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_cancel_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    $form->{type}->set_text("");
    $form->{cost}->set_text("");
    Gtk->main_quit;
} # End of sub on_cancel_clicked

sub on_ok_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_ok_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    Gtk->main_quit;
} # End of sub on_ok_clicked










#==============================================================================
#=== This is the 'Subimport_window' class                              
#==============================================================================
package Subimport_window;
require 5.000; use strict 'vars', 'refs', 'subs';
# UI class 'Subimport_window' (version 0.01)
# 
# Copyright (c) Date Thu Aug 22 12:40:43 CDT 2002
# Author Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
# Unspecified copying policy, please contact the author\n#  Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
#==============================================================================
# This perl source file was automatically generated by 
# Glade::PerlGenerate version 0.56 - Wed Apr 19 02:28:58 BST 2000
# Copyright (c) Author Dermot Musgrove <dermot.musgrove\@virgin.net>
#
# from Glade file /afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/ccdb.glade
# Thu Aug 22 12:40:43 CDT 2002
#==============================================================================

BEGIN {
    use vars qw( 
                 @ISA
                 %fields
                 $VERSION
             );
    # Existing signal handler modules
    use src::CCDB;
    # We need the Gnome bindings as well
    use Gnome;
    # Uncomment the line below to enable gettext checking
#    use Glade::PerlSource;
    # Tell interpreter who we are inheriting from
    @ISA     = qw( import_window );
    # Uncomment the line below to enable gettext checking
#    @ISA      = qw( import_window Glade::PerlSource );
    $VERSION = '0.01';
    # Inherit the AUTOLOAD dynamic methods from import_window
    *AUTOLOAD = \&import_window::AUTOLOAD;
} # End of sub BEGIN

%fields = (
# Insert any extra data access methods that you want to add to 
#   our inherited super-constructor (or overload)
    USERDATA    => undef,
    VERSION     => '0.01',
);

sub DESTROY {
    # This sub will be called on object destruction
} # End of sub DESTROY

#==============================================================================
#=== Below are the overloaded class constructors
#==============================================================================
sub new {
    my $that  = shift;
    # Allow indirect constructor so that we can call eg. 
    #   $window1 = BusFrame->new; $window2 = $window1->new;
    my $class = ref($that) || $that;

    # Call our super-class constructor to get an object and reconsecrate it
    my $self = bless $that->SUPER::new(), $class;

    # Add our own data access methods to the inherited constructor
    my($element);
    foreach $element (keys %fields) {
        $self->{_permitted_fields}->{$element} = $fields{$element};
    }
    @{$self}{keys %fields} = values %fields;
    return $self;
} # End of sub new

sub run {
    my ($class, $dbh) = @_;
    return unless Gtk->main_level == 1;
    Gnome->init('CCDB', '0.01');
    # Uncomment the line below to enable gettext checking
#    $class->check_gettext_strings;
    my $window = $class->new;
    # Insert your subclass user data key/value pairs 
    $window->USERDATA({
#        'Key1'   => 'Value1',
#        'Key2'   => 'Value2',
#        'Key3'   => 'Value3',
    });
    $window->TOPLEVEL->show;
#    my $window2 = $window->new;
#    $window2->TOPLEVEL->show;
    
    # Query the database and build the paperwork menu
    my $query = $dbh->prepare("select * from ccdb_paperwork_types
    order by type");
    $query->execute;

    my $menu = new Gtk::Menu;
    my %options;
    while (my $row = $query->fetchrow_hashref)
    {
	my $item = new Gtk::MenuItem $row->{type};
	$item->show;
	$menu->append($item);
	$options{$row->{type}} = $item;
    }
    $menu->show;
    $window->{FORM}{type}->set_menu($menu);
    
    Gtk->main;
    # Uncomment the line below to enable gettext checking
#    $window->write_gettext_strings("__", '/afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/src/CCDB.pot');

    my $type;
    foreach my $option (keys %options)
    {
	next unless $options{$option} == $menu->get_active;

	$type = $option;
	last;
    }

    my $file = $window->{FORM}{file}->get_text;
    $window->{FORM}{import_window}->destroy;

    return ($type, $file);
} # End of sub run
#===============================================================================
#=== Below are (overloaded) default signal handlers for 'import_window' class 
#===============================================================================
sub about_Form {
    my ($class) = @_;
    my $gtkversion = 
        Gtk->major_version.".".
        Gtk->minor_version.".".
        Gtk->micro_version;
    my $name = $0;
    #
    # Create a Gnome::About '$ab'
    my $ab = new Gnome::About(
        "SubCCDB", 
        "0.01", 
        _("Copyright")." Thu Aug 22 12:40:43 CDT 2002", 
        "Nathan Mueller <nmueller\@newton.cs.wisc.edu>", 
        _("No description")."\n".
        "Gtk ".     _("version").": $gtkversion\n".
        "Gtk-Perl "._("version").": $Gtk::VERSION\n".
        _("run from file").": $name\n".
        "# Unspecified copying policy, please contact the author\n# ", 
        "$Glade::PerlRun::pixmaps_directory/glade2perl_logo.xpm", 
    );
    $ab->set_title(_("About")." SubCCDB" );
    $ab->position('mouse' );
    $ab->set_policy(1, 1, 0 );
    $ab->set_modal(1 );
    $ab->show;
} # End of sub about_Form

sub destroy_Form {
    my ($class, $data, $object, $instance) = @_;
    Gtk->main_quit; 
} # End of sub destroy_Form

sub toplevel_hide    { shift->get_toplevel->hide    }
sub toplevel_close   { shift->get_toplevel->close   }
sub toplevel_destroy { shift->get_toplevel->destroy }


#==============================================================================
#=== Below are (overloaded) signal handlers for 'import_window' class 
#==============================================================================
sub on_browse_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_browse_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    my $file = Subfile_selection->run;
    $form->{file}->set_text($file)
	if $file;
} # End of sub on_browse_clicked

sub on_cancel_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_cancel_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    $form->{file}->set_text("");
    Gtk->main_quit;
} # End of sub on_cancel_clicked

sub on_ok_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_ok_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    Gtk->main_quit;
} # End of sub on_ok_clicked










#==============================================================================
#=== This is the 'Subfolder_window' class                              
#==============================================================================
package Subfolder_window;
require 5.000; use strict 'vars', 'refs', 'subs';
# UI class 'Subfolder_window' (version 0.01)
# 
# Copyright (c) Date Thu Aug 22 12:40:43 CDT 2002
# Author Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
# Unspecified copying policy, please contact the author\n#  Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
#==============================================================================
# This perl source file was automatically generated by 
# Glade::PerlGenerate version 0.56 - Wed Apr 19 02:28:58 BST 2000
# Copyright (c) Author Dermot Musgrove <dermot.musgrove\@virgin.net>
#
# from Glade file /afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/ccdb.glade
# Thu Aug 22 12:40:43 CDT 2002
#==============================================================================

BEGIN {
    use vars qw( 
                 @ISA
                 %fields
                 $VERSION
             );
    # Existing signal handler modules
    use src::CCDB;
    # We need the Gnome bindings as well
    use Gnome;
    # Uncomment the line below to enable gettext checking
#    use Glade::PerlSource;
    # Tell interpreter who we are inheriting from
    @ISA     = qw( folder_window );
    # Uncomment the line below to enable gettext checking
#    @ISA      = qw( folder_window Glade::PerlSource );
    $VERSION = '0.01';
    # Inherit the AUTOLOAD dynamic methods from folder_window
    *AUTOLOAD = \&folder_window::AUTOLOAD;
} # End of sub BEGIN

%fields = (
# Insert any extra data access methods that you want to add to 
#   our inherited super-constructor (or overload)
    USERDATA    => undef,
    VERSION     => '0.01',
);

sub DESTROY {
    # This sub will be called on object destruction
} # End of sub DESTROY

#==============================================================================
#=== Below are the overloaded class constructors
#==============================================================================
sub new {
    my $that  = shift;
    # Allow indirect constructor so that we can call eg. 
    #   $window1 = BusFrame->new; $window2 = $window1->new;
    my $class = ref($that) || $that;

    # Call our super-class constructor to get an object and reconsecrate it
    my $self = bless $that->SUPER::new(), $class;

    # Add our own data access methods to the inherited constructor
    my($element);
    foreach $element (keys %fields) {
        $self->{_permitted_fields}->{$element} = $fields{$element};
    }
    @{$self}{keys %fields} = values %fields;
    return $self;
} # End of sub new

sub run {
    my ($class) = @_;
    return unless Gtk->main_level == 1;
    Gnome->init('CCDB', '0.01');
    # Uncomment the line below to enable gettext checking
#    $class->check_gettext_strings;
    my $window = $class->new;
    # Insert your subclass user data key/value pairs 
    $window->USERDATA({
#        'Key1'   => 'Value1',
#        'Key2'   => 'Value2',
#        'Key3'   => 'Value3',
    });
    $window->TOPLEVEL->show;
#    my $window2 = $window->new;
#    $window2->TOPLEVEL->show;
    Gtk->main;
    # Uncomment the line below to enable gettext checking
#    $window->write_gettext_strings("__", '/afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/src/CCDB.pot');
    my $name = $window->{FORM}{number}->get_text;
    $window->{FORM}{folder_window}->destroy;
    return $name;
} # End of sub run
#===============================================================================
#=== Below are (overloaded) default signal handlers for 'folder_window' class 
#===============================================================================
sub about_Form {
    my ($class) = @_;
    my $gtkversion = 
        Gtk->major_version.".".
        Gtk->minor_version.".".
        Gtk->micro_version;
    my $name = $0;
    #
    # Create a Gnome::About '$ab'
    my $ab = new Gnome::About(
        "SubCCDB", 
        "0.01", 
        _("Copyright")." Thu Aug 22 12:40:43 CDT 2002", 
        "Nathan Mueller <nmueller\@newton.cs.wisc.edu>", 
        _("No description")."\n".
        "Gtk ".     _("version").": $gtkversion\n".
        "Gtk-Perl "._("version").": $Gtk::VERSION\n".
        _("run from file").": $name\n".
        "# Unspecified copying policy, please contact the author\n# ", 
        "$Glade::PerlRun::pixmaps_directory/glade2perl_logo.xpm", 
    );
    $ab->set_title(_("About")." SubCCDB" );
    $ab->position('mouse' );
    $ab->set_policy(1, 1, 0 );
    $ab->set_modal(1 );
    $ab->show;
} # End of sub about_Form

sub destroy_Form {
    my ($class, $data, $object, $instance) = @_;
    Gtk->main_quit; 
} # End of sub destroy_Form

sub toplevel_hide    { shift->get_toplevel->hide    }
sub toplevel_close   { shift->get_toplevel->close   }
sub toplevel_destroy { shift->get_toplevel->destroy }


#==============================================================================
#=== Below are (overloaded) signal handlers for 'folder_window' class 
#==============================================================================
sub on_cancel_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_cancel_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    $form->{name}->set_text("");
    Gtk->main_quit;
} # End of sub on_cancel_clicked

sub on_ok_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_ok_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    Gtk->main_quit;
} # End of sub on_ok_clicked










#==============================================================================
#=== This is the 'Subsplit_parts_window' class                              
#==============================================================================
package Subsplit_parts_window;
require 5.000; use strict 'vars', 'refs', 'subs';
# UI class 'Subsplit_parts_window' (version 0.01)
# 
# Copyright (c) Date Tue Aug 27 13:14:24 CDT 2002
# Author Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
# Unspecified copying policy, please contact the author\n#  Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
#==============================================================================
# This perl source file was automatically generated by 
# Glade::PerlGenerate version 0.56 - Wed Apr 19 02:28:58 BST 2000
# Copyright (c) Author Dermot Musgrove <dermot.musgrove\@virgin.net>
#
# from Glade file /afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/ccdb.glade
# Tue Aug 27 13:14:24 CDT 2002
#==============================================================================

BEGIN {
    use vars qw( 
                 @ISA
                 %fields
                 $VERSION
             );
    # Existing signal handler modules
    use src::CCDB;
    # We need the Gnome bindings as well
    use Gnome;
    # Uncomment the line below to enable gettext checking
#    use Glade::PerlSource;
    # Tell interpreter who we are inheriting from
    @ISA     = qw( split_parts_window );
    # Uncomment the line below to enable gettext checking
#    @ISA      = qw( split_parts_window Glade::PerlSource );
    $VERSION = '0.01';
    # Inherit the AUTOLOAD dynamic methods from split_parts_window
    *AUTOLOAD = \&split_parts_window::AUTOLOAD;
} # End of sub BEGIN

%fields = (
# Insert any extra data access methods that you want to add to 
#   our inherited super-constructor (or overload)
    USERDATA    => undef,
    VERSION     => '0.01',
);

sub DESTROY {
    # This sub will be called on object destruction
} # End of sub DESTROY

#==============================================================================
#=== Below are the overloaded class constructors
#==============================================================================
sub new {
    my $that  = shift;
    # Allow indirect constructor so that we can call eg. 
    #   $window1 = BusFrame->new; $window2 = $window1->new;
    my $class = ref($that) || $that;

    # Call our super-class constructor to get an object and reconsecrate it
    my $self = bless $that->SUPER::new(), $class;

    # Add our own data access methods to the inherited constructor
    my($element);
    foreach $element (keys %fields) {
        $self->{_permitted_fields}->{$element} = $fields{$element};
    }
    @{$self}{keys %fields} = values %fields;
    return $self;
} # End of sub new

sub run {
    my ($class, $subject1, $subject2, %parts) = @_;
    return unless Gtk->main_level == 1;
    Gnome->init('CCDB', '0.01');
    # Uncomment the line below to enable gettext checking
#    $class->check_gettext_strings;
    my $window = $class->new;
    # Insert your subclass user data key/value pairs 
    $window->USERDATA({
#        'Key1'   => 'Value1',
#        'Key2'   => 'Value2',
#        'Key3'   => 'Value3',
    });
    $window->TOPLEVEL->show;
    
    $window->{FORM}{subject_1}->set_text($subject1);
    $window->{FORM}{subject_2}->set_text($subject2);
    foreach (keys %parts)
    {
	$window->{FORM}{part_list_1}->append($_, $parts{$_});
    }

#    my $window2 = $window->new;
#    $window2->TOPLEVEL->show;
    Gtk->main;

    my %parts1;
    foreach (0 .. $window->{FORM}{part_list_1}->rows-1)
    {
	$parts1{$window->{FORM}{part_list_1}->get_text($_, 0)} = $window->{FORM}{part_list_1}->get_text($_, 1);
    }

    my %parts2;
    foreach (0 .. $window->{FORM}{part_list_2}->rows-1)
    {
	$parts2{$window->{FORM}{part_list_2}->get_text($_, 0)} = $window->{FORM}{part_list_2}->get_text($_, 1);
    }
    $window->{FORM}{split_parts_window}->destroy;

    # Uncomment the line below to enable gettext checking
#    $window->write_gettext_strings("__", '/afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/src/CCDB.pot');
    return (\%parts1, \%parts2);
} # End of sub run
#===============================================================================
#=== Below are (overloaded) default signal handlers for 'split_parts_window' class 
#===============================================================================
sub about_Form {
    my ($class) = @_;
    my $gtkversion = 
        Gtk->major_version.".".
        Gtk->minor_version.".".
        Gtk->micro_version;
    my $name = $0;
    #
    # Create a Gnome::About '$ab'
    my $ab = new Gnome::About(
        "SubCCDB", 
        "0.01", 
        _("Copyright")." Tue Aug 27 13:14:24 CDT 2002", 
        "Nathan Mueller <nmueller\@newton.cs.wisc.edu>", 
        _("No description")."\n".
        "Gtk ".     _("version").": $gtkversion\n".
        "Gtk-Perl "._("version").": $Gtk::VERSION\n".
        _("run from file").": $name\n".
        "# Unspecified copying policy, please contact the author\n# ", 
        "$Glade::PerlRun::pixmaps_directory/glade2perl_logo.xpm", 
    );
    $ab->set_title(_("About")." SubCCDB" );
    $ab->position('mouse' );
    $ab->set_policy(1, 1, 0 );
    $ab->set_modal(1 );
    $ab->show;
} # End of sub about_Form

sub destroy_Form {
    my ($class, $data, $object, $instance) = @_;
    Gtk->main_quit; 
} # End of sub destroy_Form

sub toplevel_hide    { shift->get_toplevel->hide    }
sub toplevel_close   { shift->get_toplevel->close   }
sub toplevel_destroy { shift->get_toplevel->destroy }


#==============================================================================
#=== Below are (overloaded) signal handlers for 'split_parts_window' class 
#==============================================================================
sub on_cancel_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_cancel_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    $form->{part_list_1}->clear;
    $form->{part_list_2}->clear;
    Gtk->main_quit;
} # End of sub on_cancel_clicked

sub on_move_all_left_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_move_all_left_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    my $row = $form->{part_list_2}->selection;
    my $part = $form->{part_list_2}->get_text($row, 0);
    my $num = $form->{part_list_2}->get_text($row, 1);
    $form->{part_list_2}->remove($row);

    foreach (0 .. $form->{part_list_1}->rows)
    {
	next unless $form->{part_list_1}->get_text($_, 0) eq $part;

	$form->{part_list_1}->set_text($_, 1,
				       $form->{part_list_1}->get_text($_,
				       1) + $num);
	return;
    }
    $form->{part_list_1}->append($part, $num);
} # End of sub on_move_all_left_clicked

sub on_move_all_right_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_move_all_right_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    my $row = $form->{part_list_1}->selection;
    my $part = $form->{part_list_1}->get_text($row, 0);
    my $num = $form->{part_list_1}->get_text($row, 1);
    $form->{part_list_1}->remove($row);

    foreach (0 .. $form->{part_list_2}->rows)
    {
	next unless $form->{part_list_2}->get_text($_, 0) eq $part;

	$form->{part_list_2}->set_text($_, 1,
				       $form->{part_list_2}->get_text($_,
				       1) + $num);
	return;
    }
    $form->{part_list_2}->append($part, $num);
} # End of sub on_move_all_right_clicked

sub on_move_some_left_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_move_some_left_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    my $row = $form->{part_list_2}->selection;
    my $part = $form->{part_list_2}->get_text($row, 0);
    my $num = $form->{part_list_2}->get_text($row, 1);
    my $quantity = $form->{quantity}->get_text;
    $form->{quantity}->set_text("");

    if ($quantity > $num)
    {
	my $box = Gnome::MessageBox->new("Can't move more parts then there are available", "error", "Ok");
	$box->show;
	return;
    }
    elsif ($quantity == $num)
    {
	$form->{part_list_2}->remove($row);
    }
    else
    {
	$form->{part_list_2}->set_text($row, 1, $num-$quantity);
    }

    foreach (0 .. $form->{part_list_1}->rows)
    {
	next unless $form->{part_list_1}->get_text($_, 0) eq $part;

	$form->{part_list_1}->set_text($_, 1,
				       $form->{part_list_1}->get_text($_,
				       1) + $quantity);
	return;
    }
    $form->{part_list_1}->append($part, $quantity);
} # End of sub on_move_some_left_clicked

sub on_move_some_right_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_move_some_right_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    my $row = $form->{part_list_1}->selection;
    my $part = $form->{part_list_1}->get_text($row, 0);
    my $num = $form->{part_list_1}->get_text($row, 1);
    my $quantity = $form->{quantity}->get_text;
    $form->{quantity}->set_text("");

    if ($quantity > $num)
    {
	my $box = Gnome::MessageBox->new("Can't move more parts then there are available", "error", "Ok");
	$box->show;
	return;
    }
    elsif ($quantity == $num)
    {
	$form->{part_list_1}->remove($row);
    }
    else
    {
	$form->{part_list_1}->set_text($row, 1, $num-$quantity);
    }

    foreach (0 .. $form->{part_list_2}->rows)
    {
	next unless $form->{part_list_2}->get_text($_, 0) eq $part;

	$form->{part_list_2}->set_text($_, 1,
				       $form->{part_list_2}->get_text($_,
				       1) + $quantity);
	return;
    }
    $form->{part_list_2}->append($part, $quantity);
} # End of sub on_move_some_right_clicked

sub on_ok_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_ok_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    Gtk->main_quit;
} # End of sub on_ok_clicked










#==============================================================================
#=== This is the 'Subfund_window' class                              
#==============================================================================
package Subfund_window;
require 5.000; use strict 'vars', 'refs', 'subs';
# UI class 'Subfund_window' (version 0.01)
# 
# Copyright (c) Date Thu Aug 22 12:40:43 CDT 2002
# Author Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
# Unspecified copying policy, please contact the author\n#  Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
#==============================================================================
# This perl source file was automatically generated by 
# Glade::PerlGenerate version 0.56 - Wed Apr 19 02:28:58 BST 2000
# Copyright (c) Author Dermot Musgrove <dermot.musgrove\@virgin.net>
#
# from Glade file /afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/ccdb.glade
# Thu Aug 22 12:40:43 CDT 2002
#==============================================================================

BEGIN {
    use vars qw( 
                 @ISA
                 %fields
                 $VERSION
             );
    # Existing signal handler modules
    use src::CCDB;
    # We need the Gnome bindings as well
    use Gnome;
    # Uncomment the line below to enable gettext checking
#    use Glade::PerlSource;
    # Tell interpreter who we are inheriting from
    @ISA     = qw( fund_window );
    # Uncomment the line below to enable gettext checking
#    @ISA      = qw( fund_window Glade::PerlSource );
    $VERSION = '0.01';
    # Inherit the AUTOLOAD dynamic methods from fund_window
    *AUTOLOAD = \&fund_window::AUTOLOAD;
} # End of sub BEGIN

%fields = (
# Insert any extra data access methods that you want to add to 
#   our inherited super-constructor (or overload)
    USERDATA    => undef,
    VERSION     => '0.01',
);

sub DESTROY {
    # This sub will be called on object destruction
} # End of sub DESTROY

#==============================================================================
#=== Below are the overloaded class constructors
#==============================================================================
sub new {
    my $that  = shift;
    # Allow indirect constructor so that we can call eg. 
    #   $window1 = BusFrame->new; $window2 = $window1->new;
    my $class = ref($that) || $that;

    # Call our super-class constructor to get an object and reconsecrate it
    my $self = bless $that->SUPER::new(), $class;

    # Add our own data access methods to the inherited constructor
    my($element);
    foreach $element (keys %fields) {
        $self->{_permitted_fields}->{$element} = $fields{$element};
    }
    @{$self}{keys %fields} = values %fields;
    return $self;
} # End of sub new

sub run {
    my ($class, $fund, $amount) = @_;
    return unless Gtk->main_level == 1;
    Gnome->init('CCDB', '0.01');
    # Uncomment the line below to enable gettext checking
#    $class->check_gettext_strings;
    my $window = $class->new;
    # Insert your subclass user data key/value pairs 
    $window->USERDATA({
#        'Key1'   => 'Value1',
#        'Key2'   => 'Value2',
#        'Key3'   => 'Value3',
    });
    $window->TOPLEVEL->show;
#    my $window2 = $window->new;
#    $window2->TOPLEVEL->show;
    
    $window->{FORM}{fund}->set_text($fund);
    $window->{FORM}{amount}->set_text($amount);

    Gtk->main;
    # Uncomment the line below to enable gettext checking
#    $window->write_gettext_strings("__", '/afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/src/CCDB.pot');
    my $fund = $window->{FORM}{fund}->get_text;
    (my $amount = $window->{FORM}{amount}->get_text) =~ s/\$//; 
    $window->{FORM}{fund_window}->destroy;
    return ($fund, $amount);
} # End of sub run
#===============================================================================
#=== Below are (overloaded) default signal handlers for 'fund_window' class 
#===============================================================================
sub about_Form {
    my ($class) = @_;
    my $gtkversion = 
        Gtk->major_version.".".
        Gtk->minor_version.".".
        Gtk->micro_version;
    my $name = $0;
    #
    # Create a Gnome::About '$ab'
    my $ab = new Gnome::About(
        "SubCCDB", 
        "0.01", 
        _("Copyright")." Thu Aug 22 12:40:43 CDT 2002", 
        "Nathan Mueller <nmueller\@newton.cs.wisc.edu>", 
        _("No description")."\n".
        "Gtk ".     _("version").": $gtkversion\n".
        "Gtk-Perl "._("version").": $Gtk::VERSION\n".
        _("run from file").": $name\n".
        "# Unspecified copying policy, please contact the author\n# ", 
        "$Glade::PerlRun::pixmaps_directory/glade2perl_logo.xpm", 
    );
    $ab->set_title(_("About")." SubCCDB" );
    $ab->position('mouse' );
    $ab->set_policy(1, 1, 0 );
    $ab->set_modal(1 );
    $ab->show;
} # End of sub about_Form

sub destroy_Form {
    my ($class, $data, $object, $instance) = @_;
    Gtk->main_quit; 
} # End of sub destroy_Form

sub toplevel_hide    { shift->get_toplevel->hide    }
sub toplevel_close   { shift->get_toplevel->close   }
sub toplevel_destroy { shift->get_toplevel->destroy }


#==============================================================================
#=== Below are (overloaded) signal handlers for 'fund_window' class 
#==============================================================================
sub on_cancel_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_cancel_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    $form->{fund}->set_text("");
    $form->{amount}->set_text("");
    Gtk->main_quit;
} # End of sub on_cancel_clicked

sub on_ok_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_ok_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    Gtk->main_quit;
} # End of sub on_ok_clicked










#==============================================================================
#=== This is the 'Submain_window' class                              
#==============================================================================
package Submain_window;
require 5.000; use strict 'vars', 'refs', 'subs';
use CSL::Pg;
use DBI;
use Mail::Send;
use MIME::Entity;
use IO::File;
use Data::Dumper;
use lib "/s/req-2/perl5";
use Req;

# UI class 'Submain_window' (version 0.01)
# 
# Copyright (c) Date Thu Aug 22 12:40:43 CDT 2002
# Author Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
# Unspecified copying policy, please contact the author\n#  Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
#==============================================================================
# This perl source file was automatically generated by 
# Glade::PerlGenerate version 0.56 - Wed Apr 19 02:28:58 BST 2000
# Copyright (c) Author Dermot Musgrove <dermot.musgrove\@virgin.net>
#
# from Glade file /afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/ccdb.glade
# Thu Aug 22 12:40:43 CDT 2002
#==============================================================================

BEGIN {
    use vars qw( 
                 @ISA
                 %fields
                 $VERSION
             );
    # Existing signal handler modules
    use src::CCDB;
    # We need the Gnome bindings as well
    use Gnome;
    # Uncomment the line below to enable gettext checking
#    use Glade::PerlSource;
    # Tell interpreter who we are inheriting from
    @ISA     = qw( main_window );
    # Uncomment the line below to enable gettext checking
#    @ISA      = qw( main_window Glade::PerlSource );
    $VERSION = '0.01';
    # Inherit the AUTOLOAD dynamic methods from main_window
    *AUTOLOAD = \&main_window::AUTOLOAD;
} # End of sub BEGIN

%fields = (
# Insert any extra data access methods that you want to add to 
#   our inherited super-constructor (or overload)
    USERDATA    => undef,
    VERSION     => '0.01',
);

sub DESTROY {
    # This sub will be called on object destruction
} # End of sub DESTROY

#==============================================================================
#=== Below are the overloaded class constructors
#==============================================================================
sub new {
    my $that  = shift;
    # Allow indirect constructor so that we can call eg. 
    #   $window1 = BusFrame->new; $window2 = $window1->new;
    my $class = ref($that) || $that;

    # Call our super-class constructor to get an object and reconsecrate it
    my $self = bless $that->SUPER::new(), $class;

    # Add our own data access methods to the inherited constructor
    my($element);
    foreach $element (keys %fields) {
        $self->{_permitted_fields}->{$element} = $fields{$element};
    }
    @{$self}{keys %fields} = values %fields;
    return $self;
} # End of sub new

sub run {
    my ($class) = @_;
    Gnome->init('CCDB', '0.01');
    # Uncomment the line below to enable gettext checking
#    $class->check_gettext_strings;
    my $window = $class->new;
    # Insert your subclass user data key/value pairs 
    $window->USERDATA({
#        'Key1'   => 'Value1',
#        'Key2'   => 'Value2',
#        'Key3'   => 'Value3',
    });
    $window->TOPLEVEL->show;

    # Set up initial stuff
    $window->{FORM}{dbh} = DBI->connect("dbi:Pg:dbname=csdb;host=onnophris;port=49170");
    $window->{FORM}{dbh}{ShowErrorStatement} = 1;
    $window->{FORM}{dbh}{PrintError} = 0;
    $window->{FORM}{dbh}{RaiseError} = 0;
    $window->{FORM}{dbh}{AutoCommit} = 1;
    $window->{FORM}{dbh}{HandleError} = \&dbi_error;

    $window->{FORM}{order_list}->set_line_style("none");
    $window->{FORM}{order_list}->set_expander_style("triangle");
    &refresh_orders($window->{FORM});
    $window->{FORM}{status_buttons}->hide;
    $window->{FORM}{order_list}->set_column_justification(4, "right");
    $window->{FORM}{part_list}->set_column_justification(3, "right");
    $window->{FORM}{order_list}->set_column_justification(5, "center");

    # Set up signal handlers for the option menues (why glade can't do
    # this I don't know)
    $window->{FORM}{order_view_item0}->signal_connect('activate', 
						      \&on_order_view_clicked,
						      '',
						      'order_view', 
						      'main_window-1');
    $window->{FORM}{order_view_item1}->signal_connect('activate', 
						      \&on_order_view_clicked, 
						      '',
						      'order_view', 
						      'main_window-1');
    $window->{FORM}{order_view_mode_item0}->signal_connect('activate', 
							    \&on_order_view_mode_clicked, 
							   '',
							    'order_view_mode', 
							    'main_window-1');
    $window->{FORM}{order_view_mode_item1}->signal_connect('activate', 
							   \&on_order_view_mode_clicked, 
							   '',
							   'order_view_mode', 
							   'main_window-1');

    # Listen for changes to the database
    Gtk->timeout_add(100, \&check_refresh, $window->{FORM});

#    my $window2 = $window->new;
#    $window2->TOPLEVEL->show;
    Gtk->main;
    # Uncomment the line below to enable gettext checking
#    $window->write_gettext_strings("__", '/afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/src/CCDB.pot');
    return $window;
} # End of sub run
#===============================================================================
#=== Below are (overloaded) default signal handlers for 'main_window' class 
#===============================================================================
sub about_Form {
    my ($class) = @_;
    my $gtkversion = 
        Gtk->major_version.".".
        Gtk->minor_version.".".
        Gtk->micro_version;
    my $name = $0;
    #
    # Create a Gnome::About '$ab'
    my $ab = new Gnome::About(
        "SubCCDB", 
        "0.01", 
        _("Copyright")." Thu Aug 22 12:40:43 CDT 2002", 
        "Nathan Mueller <nmueller\@newton.cs.wisc.edu>", 
        _("No description")."\n".
        "Gtk ".     _("version").": $gtkversion\n".
        "Gtk-Perl "._("version").": $Gtk::VERSION\n".
        _("run from file").": $name\n".
        "# Unspecified copying policy, please contact the author\n# ", 
        "$Glade::PerlRun::pixmaps_directory/glade2perl_logo.xpm", 
    );
    $ab->set_title(_("About")." SubCCDB" );
    $ab->position('mouse' );
    $ab->set_policy(1, 1, 0 );
    $ab->set_modal(1 );
    $ab->show;
} # End of sub about_Form

sub destroy_Form {
    my ($class, $data, $object, $instance) = @_;
    Gtk->main_quit; 
} # End of sub destroy_Form

sub toplevel_hide    { shift->get_toplevel->hide    }
sub toplevel_close   { shift->get_toplevel->close   }
sub toplevel_destroy { shift->get_toplevel->destroy }


#==============================================================================
#=== Below are (overloaded) signal handlers for 'main_window' class 
#==============================================================================
sub on_add_fund_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_add_fund_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    unless (&get_current_order($form))
    {
	my $box = Gnome::MessageBox->new("Please select an order", "error", "Ok");
        $box->show;
        return;
    }
    
    my ($fund, $amount) = Subfund_window->run;
    return unless $fund && $amount;
    
    # Check for already charging to the fund
    foreach (0 .. $form->{part_list}->rows)
    {
	next unless $form->{part_list}->get_row_data($_);
	return if $form->{part_list}->get_row_data($_)->{fund} eq $fund;
    }

    &begin($form->{dbh});
    
    if ($amount =~ /a/i)
    {
	my $query = $form->{dbh}->prepare("insert into ccdb_funds
    select request, sum(cost*quantity), ? from req_requests,
    ccdb_parts where number = ? and master = 't' and
    request = purchase group by request");
	$query->execute($fund, &get_current_order($form));
    }
    else
    {
	my $query = $form->{dbh}->prepare("insert into ccdb_funds select
    request, ?, ? from req_requests where number = ? and master = 't'");
	$query->execute($amount, $fund, &get_current_order($form));
    }

    &commit($form->{dbh});

    &load_order($form, &get_current_order($form));
} # End of sub on_add_fund_clicked

sub on_add_part_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_add_part_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    unless (&get_current_order($form))
    {
	my $box = Gnome::MessageBox->new("Please select an order", "error", "Ok");
        $box->show;
        return;
    }

    my ($part, $cost, $quantity) = Subpart_window->run;
    return unless $part && $cost && $quantity;
    
    # Check for pre-existing part
    foreach (0 .. $form->{part_list}->rows)
    {
	next unless $form->{part_list}->get_row_data($_);
	return if $form->{part_list}->get_row_data($_)->{part} eq $part;
    }
    
    &begin($form->{dbh});
    my $query = $form->{dbh}->prepare("insert into ccdb_parts select
    ?, ?, ?, request, null, null, null from req_requests where number
    = ? and master = 't'");
    $query->execute($part, $cost, $quantity, &get_current_order($form));
    &commit($form->{dbh});

    &load_order($form, &get_current_order($form));
} # End of sub on_add_part_clicked

sub on_add_shipping_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_add_shipping_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    unless (&get_current_order($form))
    {
	my $box = Gnome::MessageBox->new("Please select an order", "error", "Ok");
        $box->show;
        return;
    }

    my ($type, $cost) = Subshipping_window->run;
    return unless $cost;

    &begin($form->{dbh});
    my $query = $form->{dbh}->prepare("insert into ccdb_parts select
    ?, ?, 1, request, null, null, null from req_requests where number
    = ? and master = 't'");
    $query->execute("Shipping: $type", $cost, &get_current_order($form));
    &commit($form->{dbh});

    &load_order($form, &get_current_order($form));
} # End of sub on_add_shipping_clicked

sub on_cancel_order_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_cancel_order_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    unless (&get_current_order($form))
    {
	my $box = Gnome::MessageBox->new("Please select an order", "error", "Ok");
        $box->show;
        return;
    }

    # NEED #
    # Ask for confirmation
    
    &begin($form->{dbh});
    my $query = $form->{dbh}->prepare("delete from req_attributes
     where request = (select request from req_requests where number =
     ? and master = 't') and attribute = 'Purchase Req'");
    $query->execute(&get_current_order($form));
    &commit($form->{dbh});

    &refresh_orders($form);
} # End of sub on_cancel_order_clicked

sub on_convert_req_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_convert_req_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    my ($number, $subject, $vendor, $card, $user) = Subconvert_req_window->run;
    return unless $number;

    my $req = new Req;
    my $child_number = $req->create($subject);
    $req->add_requester($child_number, $user);
    $req->owner($child_number, "csladmin");
    $req->add_child($number, $child_number);
    $req->add_message($child_number, "\n\nThis is a purchase req.  Use ccdb to view it", "open");

    my $query = $form->{dbh}->prepare("insert into req_attributes
    select request, 'Purchase Req', ? from req_requests where
    number = ? and master = 't'");
    my $rows = $query->execute($vendor, $child_number);
    
    if ($rows eq "0E0")
    {
	my $error = Gnome::MessageBox->new("Can't find req #$number",
    "error", "Ok");
	$error->show;
    }
    
    &begin($form->{dbh});
    $query = $form->{dbh}->prepare("insert into req_attributes
    select request, 'Purchasing Card', ? from req_requests where
    number = ? and master = 't'");
    $query->execute($card, $child_number);
    &commit($form->{dbh});

    &refresh_orders($form, $child_number);
} # End of sub on_convert_req_clicked

sub on_delete_fund_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_delete_fund_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    unless (&get_current_order($form))
    {
	my $box = Gnome::MessageBox->new("Please select an order", "error", "Ok");
        $box->show;
        return;
    }

    my $fund = $form->{part_list}->get_row_data($form->{part_list}->selection);
    return unless $fund && exists $fund->{fund};
    
    &begin($form->{dbh});
    my $query = $form->{dbh}->prepare("delete from ccdb_funds where
    purchase = (select request from req_requests where number = ? and
    master = 't') and
    fund = ?");
    $query->execute(&get_current_order($form), $fund->{fund});
    &commit($form->{dbh});

    &load_order($form, &get_current_order($form));
} # End of sub on_delete_fund_clicked

sub on_delete_part_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_delete_part_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    unless (&get_current_order($form))
    {
	my $box = Gnome::MessageBox->new("Please select an order", "error", "Ok");
        $box->show;
        return;
    }

    my $part = $form->{part_list}->get_row_data($form->{part_list}->selection);
    return unless $part && exists $part->{part};
    
    &begin($form->{dbh});
    my $query = $form->{dbh}->prepare("delete from ccdb_parts where
    purchase = (select request from req_requests where number = ? and
    master = 't') and
    part = ?");
    $query->execute(&get_current_order($form), $part->{part});
    &commit($form->{dbh});

    &load_order($form, &get_current_order($form));
} # End of sub on_delete_part_clicked

sub on_delete_shipping_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_delete_shipping_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    unless (&get_current_order($form))
    {
	my $box = Gnome::MessageBox->new("Please select an order", "error", "Ok");
        $box->show;
        return;
    }

    &begin($form->{dbh});
    my $query = $form->{dbh}->prepare("delete from ccdb_parts where
    purchase = (select request from req_requests where number = ? and
    master = 't') and
    part like 'Shipping%'");
    $query->execute(&get_current_order($form));
    &commit($form->{dbh});

    &load_order($form, &get_current_order($form));
} # End of sub on_delete_shipping_clicked

sub on_import_paperwork_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_import_paperwork_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    my ($type, $file) = Subimport_window->run($form->{dbh});
    return unless $file;

    my $req = &get_current_order($form);

    my $ent = MIME::Entity->build(Subject => "[CSL #$req] $type", 
				  To => 'lab@cs.wisc.edu',
				  Data => 'CCDB Paperwork');

    my $data;
    if (-e $file)
    {
	my $file_fh = new IO::File $file;
	$data = join("", <$file_fh>);
    }
    elsif ($file !~ /^\d+$/)
    {
	my $box = Gnome::MessageBox->new("Can't file the file $file", "error", "Ok");
	$box->show;
	return;
    }	

    if ($file =~ /^\d+$/)
    {
	&begin($form->{dbh});
	my $query = $form->{dbh}->prepare("update req_messages set subject = ? from req_messages m where req_messages.message = m.message and m.request = (select request from req_requests where number = ? and master = 't') and (select count(*) from req_messages n where n.request = (select request from req_requests where number = ? and master = 't') and n.time <= m.time) = ?");
	$query->execute($type, $req, $req, $file);
	&commit($form->{dbh});
	return;
    }
    else
    {
	chomp(my $type = `file -i $file`);
	$type =~ s/.*: //;
	$type ||= "text/plain";
	$ent->attach(Type => $type,
		     Data => $data);
    }

    my $msg = Mail::Send->new(Subject => "[CSL #$req] $type", 
			      To => 'nate@cs.wisc.edu');
    foreach ($ent->head->tags)
    {
	$msg->set($_, map { chomp $_;$_ } $ent->head->get($_));
    }
    my $fh = $msg->open;
    $ent->print_body($fh);
    $fh->close;
} # End of sub on_import_paperwork_clicked

sub on_main_window_destroy {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_main_window_destroy";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};
    
    Gtk->exit(0);
} # End of sub on_main_window_destroy

sub on_no_inventory_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_no_inventory_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};
    
    unless (defined $form->{part_list}->selection)
    {
	my $box = Gnome::MessageBox->new("You need to select a part to mark as not inventoried", "error", "Ok");
	$box->show;
	return;
    }

    &begin($form->{dbh});
    my $query = $form->{dbh}->prepare("update ccdb_parts set inventoried =
? from req_requests where request = purchase and
number = ? and master = 't' and part = ?");
    $query->execute(-1, &get_current_order($form), $form->{part_list}->get_row_data($form->{part_list}->selection)->{part});
    &commit($form->{dbh});

    my $selection = $form->{part_list}->selection;
    &load_order($form, &get_current_order($form));
    $form->{part_list}->select_row($selection, 0);
} # End of sub on_no_inventory_clicked

sub on_order_list_button_press_event {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_order_list_button_press_event";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    # We only care about double clicks
    $form->{order_last_select} = $form->{order_list}->selection
	if $form->{order_list}->selection;
    return unless ($event->{type} eq "2button_press"
		   && $event->{button} == 1);
    my $selected = $form->{order_list}->selection;
    unless ($selected)
    {
	$selected = $form->{order_last_select};
	$form->{order_list}->select_row($selected, 0);
    }
    my $mesg = $form->{order_list}->node_get_row_data($selected);
    return unless $$mesg =~ /\D/;

    my $type = $form->{order_list}->get_text($selected, 1);
    
    # NEED #
    # A better way to do this
    # Mime decode the message and figure out the type
    mkdir "/tmp/$<";
    `rm -f /tmp/$</*`;
    system("cp $$mesg /tmp/$</mesg");
    `munpack -t -C /tmp/$< mesg`;
    if (`file /tmp/$</part2` =~ /(ASCII|smtp)/)
    {
	system("xterm -title \"$type\" -e tcsh -c \"less /tmp/$</part2\" &");
    }
    elsif (-e "/tmp/$</part2")
    {
	system("xv /tmp/$</part2 &");
    }
    else
    {
	system("xterm -title \"$type\" -e tcsh -c \"less /tmp/$</mesg\" &");
    }
} # End of sub on_order_list_button_press_event

sub on_order_list_tree_select_row {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_order_list_tree_select_row";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    # See if it's paid
    my $order = &get_current_order($form);
    my $query = $form->{dbh}->prepare("select * from req_requests,
    req_attributes where number = ? and req_requests.request =
    req_attributes.request and req_attributes.attribute = 'Purchase Checked' and master = 't'");
    $query->execute($order);
    if ($query->fetchrow)
    {
	$form->{paid_label}->set_text("Mark As Unpaid");
    }
    else
    {
	$form->{paid_label}->set_text("Mark As Paid");
    }

    &load_order($form, &get_current_order($form));
} # End of sub on_order_list_tree_select_row

sub on_order_view_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_order_view_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    &refresh_orders($form);
} # End of sub on_order_view_clicked

sub on_order_view_mode_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_order_view_mode_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    if ($form->{order_view_mode}->get_menu->get_active == $form->{order_view_mode_item0})
    {
	$form->{status_buttons}->hide;
	$form->{detail_buttons}->show;
	$form->{label24}->set_text("Part");
	$form->{label25}->set_text("Quantity Ordered");
	$form->{label26}->set_text("Unit Cost");
	$form->{label27}->set_text("Total Cost");
	$form->{part_list}->set_column_justification(3, "right");
    }
    else
    {
	$form->{status_buttons}->show;
	$form->{detail_buttons}->hide;
	$form->{label24}->set_text("Part");
	$form->{label25}->set_text("Quantity Ordered");
	$form->{label26}->set_text("Quantity Arrived");
	$form->{label27}->set_text("Quantity Inventoried");
	$form->{part_list}->set_column_justification(3, "left");
    }

    &load_order($form, &get_current_order($form));
} # End of sub on_order_view_mode_clicked

sub on_paid_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_paid_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    my $order = &get_current_order($form);

    # See if it's paid
    my $query = $form->{dbh}->prepare("select * from req_requests,
    req_attributes where number = ? and req_requests.request =
    req_attributes.request and req_attributes.attribute = 'Purchase Checked' and master = 't'");
    $query->execute($order);
    
    &begin($form->{dbh});
    if ($query->fetchrow)
    {
	$query->finish;

	$query = $form->{dbh}->prepare("delete from req_attributes
	where attribute = 'Purchase Checked' and request in (select
	request from req_requests where number = ? and master = 't')");
	$query->execute($order);
	$form->{paid_label}->set_text("Mark As Paid");
    }
    else
    {
	$query = $form->{dbh}->prepare("insert into req_attributes
	select request, 'Purchase Checked', cast(current_timestamp as
	text) from req_requests where number = ? and master = 't'");
	$query->execute($order);
	$form->{paid_label}->set_text("Mark As Unpaid");
    }
    &commit($form->{dbh});

} # End of sub on_paid_clicked

sub on_part_list_button_press_event {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_part_list_button_press_event";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    return unless $form->{order_view_mode}->get_menu->get_active == $form->{order_view_mode_item0};

    # We only care about double clicks
    $form->{last_select} = $form->{part_list}->selection
	if $form->{part_list}->selection >= 0;
    return unless ($event->{type} eq "2button_press"
		   && $event->{button} == 1);

    my $selected = $form->{part_list}->selection;
    unless ($selected)
    {
	$selected = $form->{last_select};
	$form->{part_list}->select_row($selected, 0);
    }
    my $old_thing = $form->{part_list}->get_row_data($selected);
    return unless $old_thing;

    &begin($form->{dbh});
    if (exists $old_thing->{part})
    {
	my ($part, $cost, $quantity) =
	    Subpart_window->run($old_thing->{part},
				$old_thing->{cost},
				$old_thing->{quantity});	
	return unless $part;

	my $query = $form->{dbh}->prepare("update ccdb_parts set part = ?,
    cost = ?, quantity = ? from req_requests where part = ? and
    purchase = request and number = ? and master = 't'");
	$query->execute($part, $cost, $quantity, $old_thing->{part}, &get_current_order($form));
    }
    elsif (exists $old_thing->{fund})
    {
	my ($fund, $amount) = Subfund_window->run($old_thing->{fund},
						  $old_thing->{amount});
	return unless $fund;

	my $query = $form->{dbh}->prepare("update ccdb_funds set fund = ?,
    amount = ? from req_requests where fund = ? and
    purchase = request and number = ? and master = 't'");
	$query->execute($fund, $amount, $old_thing->{fund}, &get_current_order($form));
    }
    elsif (exists $old_thing->{shipping})
    {
	my ($type, $cost) =
	    Subshipping_window->run($old_thing->{type}, $old_thing->{shipping});
	return unless $cost;

	my $query = $form->{dbh}->prepare("update ccdb_parts set cost
    = ?, part = ? from req_requests where part like 'Shipping%' and
    purchase = request and number = ? and master = 't'");
	$query->execute($cost, "Shipping: $type", &get_current_order($form));
    }
    &commit($form->{dbh});

    &load_order($form, &get_current_order($form));
} # End of sub on_part_list_button_press_event

sub on_refresh_orders_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_refresh_orders_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    &refresh_orders($form);
} # End of sub on_refresh_orders_clicked

sub on_split_order_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_split_order_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    unless (defined $form->{order_list}->selection)
    {
	my $box = Gnome::MessageBox->new("You need to select a an order to split", "error", "Ok");
	$box->show;
	return;
    }

    # Get the subject of the current req
    my $query = $form->{dbh}->prepare("select subject, value from
    req_requests, req_attributes
    where number = ? and master = 't' and req_requests.request =
    req_attributes.request and attribute = 'Purchase Req'");
    $query->execute(&get_current_order($form));
    my ($subject, $vendor) = $query->fetchrow;
    $query->finish;
    my $new_subject = $subject;
    if ($new_subject =~ /part \d+$/)
    {
	$new_subject =~ s/part (\d+)$/"part " . $1+1/e;
    }
    else
    {
	$new_subject .= " part 2";
    }

    $query = $form->{dbh}->prepare("select part, quantity from
    ccdb_parts, req_requests where purchase = request and number = ?
    and master = 't' and part not like 'Shipping%'");
    $query->execute(&get_current_order($form));
    my $result = $query->fetchall_arrayref;
    my %parts = map { $_->[0] => $_->[1] } @$result;
    my ($old, $new) = Subsplit_parts_window->run($subject, $new_subject, %parts);
    return unless $old && $new;

    # Get the parent of the current order
    my $query = $form->{dbh}->prepare("select p.number from
    req_requests p, req_requests c where c.number = ? and p.request =
    c.parent and c.master = 't' and p.master = 't'");
    $query->execute(&get_current_order($form));
    my ($parent) = $query->fetchrow;
    $query->finish;

    # Create a new req for the other half of the order    
    my $mail = new Mail::Send;
    $mail->to('lab@cs.wisc.edu');
    $mail->subject($new_subject);
    $mail->set('X-Request-Parent', $parent)
	if ($parent);
    my $mail_fh = $mail->open;
    $mail_fh->close;

    $query = $form->{dbh}->prepare("select number, request from
    req_requests where number = (select max(number) from req_requests
    where subject = ?)");
    $query->execute($new_subject);
    my ($new_req_number, $new_req_request) = $query->fetchrow;
    $query->finish;

    &begin($form->{dbh});
    $query = $form->{dbh}->prepare("insert into req_attributes values 
    (?, 'Purchase Req', ?)");
    $query->execute($new_req_request, $vendor);
    $query->finish;

    foreach my $part (keys %$new)
    {
	if (exists $old->{$part})
	{
	    $query = $form->{dbh}->prepare("update ccdb_parts set
    quantity = ? from req_requests where part = ? and request =
    purchase and number = ? and master = 't'");
	    $query->execute($old->{$part}, $part,
			    &get_current_order($form));
	    $query->finish;

	    $query = $form->{dbh}->prepare("insert into ccdb_parts
	    select ?, cost, ?, ?, null, null, comments from
	    ccdb_parts, req_requests where
	    purchase = request and number = ? and master = 't'
	    and part = ?");
	    $query->execute($part, $new->{$part}, $new_req_request,
			    &get_current_order($form), $part);
	    $query->finish;	    
	}
	else
	{
	    $query = $form->{dbh}->prepare("update ccdb_parts set
	purchase = (select request from req_requests where number = ?
	and master = 't') from req_requests where part = ? and request
	= purchase and number = ? and master = 't'");
	    $query->execute($new_req_number, $part,
			    &get_current_order($form));
	    $query->finish;
	}
    }
    &commit($form->{dbh});

} # End of sub on_split_order_clicked

sub on_toggle_arrived_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_toggle_arrived_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};
    
    unless (defined $form->{part_list}->selection)
    {
	my $box = Gnome::MessageBox->new("You need to select a part to mark as arrived", "error", "Ok");
	$box->show;
	return;
    }
    
    my $arrived = $form->{part_list}->get_text($form->{part_list}->selection, 2);
    $arrived = Subnumber_window->run($arrived, "Quantity Arrived");
    return if $arrived eq "";

    # Check if number arrived > number ordered
    my $num = $form->{part_list}->get_text($form->{part_list}->selection, 1);
    if ($num < $arrived)
    {
	my $box = Gnome::MessageBox->new("You said $arrived arrived but only $num were ordered", "error", "Ok");
	$box->show;
	return;
    }

    &begin($form->{dbh});
    my $query = $form->{dbh}->prepare("update ccdb_parts set arrived =
? from req_requests where request = purchase and
number = ? and master = 't' and part = ?");
    $query->execute($arrived, &get_current_order($form), $form->{part_list}->get_row_data($form->{part_list}->selection)->{part});
    &commit($form->{dbh});

    my $selection = $form->{part_list}->selection;
    &load_order($form, &get_current_order($form));
    $form->{part_list}->select_row($selection, 0);
} # End of sub on_toggle_arrived_clicked

sub on_toggle_inventoried_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_toggle_inventoried_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};
    
    unless (defined $form->{part_list}->selection)
    {
	my $box = Gnome::MessageBox->new("You need to select a part to mark as inventoried", "error", "Ok");
	$box->show;
	return;
    }

    my $inventoried = $form->{part_list}->get_text($form->{part_list}->selection, 3);
    $inventoried = Subnumber_window->run($inventoried, "Quantity Inventoried");
    return if $inventoried eq "";

    # Check if number arrived > number ordered
    my $num = $form->{part_list}->get_text($form->{part_list}->selection, 1);
    if ($num < $inventoried)
    {
	my $box = Gnome::MessageBox->new("You said $inventoried have been inventoried but only $num were ordered", "error", "Ok");
	$box->show;
	return;
    }

    &begin($form->{dbh});
    my $query = $form->{dbh}->prepare("update ccdb_parts set inventoried =
? from req_requests where request = purchase and
number = ? and master = 't' and part = ?");
    $query->execute($inventoried, &get_current_order($form), $form->{part_list}->get_row_data($form->{part_list}->selection)->{part});
    &commit($form->{dbh});

    my $selection = $form->{part_list}->selection;
    &load_order($form, &get_current_order($form));
    $form->{part_list}->select_row($selection, 0);
} # End of sub on_toggle_inventoried_clicked

sub check_refresh
{
    my ($form) = @_;

    #if (my $notify = $form->{dbh}->func('pg_notifies'))
    #{
#	&refresh_orders($form);
#    }

    1;
}

sub load_order
{
    my ($form, $order) = @_;

    # Pay attention to view mode
    my $query;
    my $mode;
    if ($form->{order_view_mode}->get_menu->get_active == $form->{order_view_mode_item1})
    {
	$mode = "status";
	$query = $form->{dbh}->prepare("select part, quantity, arrived, inventoried from ccdb_parts, req_requests where purchase =
    request and number = ? and part not like 'Shipping%' order by part");
	$query->execute($order);
    }
    else
    {
	$mode = "details";
	$query = $form->{dbh}->prepare("select part, quantity, cost,
    quantity*cost from ccdb_parts, req_requests where purchase =
    request and number = ? and part not like 'Shipping%' order by part");
	$query->execute($order);
    }

    $form->{part_list}->freeze;
    $form->{part_list}->clear;
    my $cost = 0;
    while (my @row = $query->fetchrow)
    {
	# Convert timestamps to real format
	if ($mode eq "status")
	{
	    foreach (@row[2,3])
	    {
		s/\..*//;
	    }
	    $row[3] = "Not Inventoried" if $row[3] == -1;
	}
	else
	{
	    $cost += $row[3];
	    foreach (@row[2,3])
	    {
		$_ = sprintf("\$%.2f", $_);
	    }
	}

	my $row = $form->{part_list}->append(@row);
	$form->{part_list}->set_row_data($row, {part => $row[0],
					        quantity => $row[1],
					        cost => $row[2]});
    }
    
    if ($mode eq "details")
    {
	$form->{part_list}->append(undef, undef, undef, "------------");
	$form->{part_list}->append(undef, undef, "Sub-total",
	sprintf("\$%.2f", $cost));
	
	$query = $form->{dbh}->prepare("select cost, part from ccdb_parts,
req_requests where purchase = request and number = ? and part like
'Shipping%'");
	$query->execute($order);
	my ($shipping, $type) = $query->fetchrow;
	$query->finish;
	my $row = $form->{part_list}->append(undef, undef, $type,
	sprintf("\$%.2f", $shipping));
	$type =~ s/Shipping: //;
	if ($shipping)
	{
	    $form->{add_shipping}->hide;
	    $form->{delete_shipping}->show;
	}
	else
	{
	    $form->{add_shipping}->show;
	    $form->{delete_shipping}->hide;
	}
	$form->{part_list}->set_row_data($row, {shipping =>
	sprintf("\$%.2f", $shipping), type => $type});
	$form->{part_list}->append(undef, undef, undef, "------------");
	$row = $form->{part_list}->append(undef, undef, "Total",
					  sprintf("\$%.2f", $shipping+$cost));
	
	$form->{part_list}->append(undef, undef, undef, "------------");
	
	$query = $form->{dbh}->prepare("select fund, amount from ccdb_funds, req_requests where purchase =
    request and number = ?");
	$query->execute($order);
	my $funds = 0;
	while (my @row = $query->fetchrow)
	{
	    $funds += $row[1];
	    $row[1] = sprintf("\$%.2f", $row[1]);
	    $row = $form->{part_list}->append(undef, undef, @row);
	    $form->{part_list}->set_row_data($row, {fund => $row[0],
						    amount => $row[1]});
	}
	
	$form->{part_list}->append(undef, undef, undef, "------------");
	$form->{part_list}->append(undef, undef, "Unassigned Balance",
	sprintf("\$%.2f", $shipping+$cost-$funds));
    }

    $form->{part_list}->thaw;
}

sub refresh_orders
{
    my ($form) = @_;

    # Listen to the desired order types
    my $state = "active";
    if ($form->{order_view}->get_menu->get_active == $form->{order_view_item1})
    {
	$state = "resolved";
    }

    # Track selection/expansion/position if it's a rescan
    my %expanded;
    my $selected;
    my $top;
    if ($form->{last_state} eq $state)
    {
	my $i;
	while (my $node = $form->{order_list}->node_nth($i))
	{
	    $i++;
	    my $data = $form->{order_list}->node_get_row_data($node);

	    $expanded{$$data} = 1
		if $node->row->expanded;

	    $top = $$data
		if $form->{order_list}->node_is_visible($node) eq "full"
		    && !$top;
        }
    
        if (my $node = $form->{order_list}->selection)
	{
	    my $data = $form->{order_list}->node_get_row_data($node);
	    $selected = $$data;
	}
    }

    $form->{last_state} = $state;

    my $query = $form->{dbh}->prepare("select number, subject, value,
age(first), '3', '4' from req_requests, req_attributes where
req_requests.request = req_attributes.request and
req_attributes.attribute = 'Purchase Req' and status = ? order by lpad(number, 25,
'0') desc");
    $query->execute($state);
    $form->{order_list}->freeze;
    $form->{order_list}->clear;
    while (my $row = $query->fetchrow_arrayref)
    {
	my $query_cost = $form->{dbh}->prepare("select
sum(cost*quantity) from ccdb_parts, req_requests where request =
purchase and number = ?");
	$query_cost->execute($row->[0]);
	($row->[4]) = sprintf("\$%.2f", $query_cost->fetchrow);
	$query_cost->finish;
	$row->[3] =~ s/\..*//;
	$row->[5] = "";
	
	# Status markers (215, 111) for:
	# Confirmation
	# Arrived
	# Invoice
	# Credit card thing
	my $status_query = $form->{dbh}->prepare("select count(*) from
        req_messages, req_requests where req_requests.request =
	req_messages.request and number = ? and req_messages.subject
	like '[CSL \#%] Confirmation' and master = 't'");
	$status_query->execute($row->[0]);
	if ($status_query->fetchrow)
	{
	    $row->[5] .= chr(215);
	}
	else
	{
	    $row->[5] .= "o";
	}
	$status_query->finish;
	$status_query = $form->{dbh}->prepare("select sum(quantity),
sum(arrived) from ccdb_parts, req_requests where request = purchase
and master = 't' and number = ? and part not like 'Shipping%'");
	$status_query->execute($row->[0]);
	my ($num, $arrived) = $status_query->fetchrow;
	if ($num == $arrived && $arrived)
	{
	    $row->[5] .= chr(215);
	}
	elsif ($arrived)
	{
	    $row->[5] .= chr(164);
	}
	else
	{
	    $row->[5] .= "o";
	}
	$status_query->finish;
	$status_query = $form->{dbh}->prepare("select count(*) from
        req_messages, req_requests where req_requests.request =
	req_messages.request and number = ? and req_messages.subject
	like '[CSL \#%] Invoice' and master = 't'");
	$status_query->execute($row->[0]);
	if ($status_query->fetchrow)
	{
	    $row->[5] .= chr(215);
	}
	else
	{
	    $row->[5] .= "o";
	}
	$status_query->finish;

	$status_query = $form->{dbh}->prepare("select * from
	req_requests, req_attributes where number = ? and
	req_requests.request = req_attributes.request and attribute =
	'Purchase Checked' and master = 't'");
	$status_query->execute($row->[0]);
	if ($status_query->fetchrow)
	{
	    $row->[5] .= chr(215);	
	}
	else
	{
	    $row->[5] .= "o";
	}

	my $node = $form->{order_list}->insert_node(undef, undef, $row, 0, undef,
						    undef, undef, undef, 0, 0);
	my $data = $row->[0];
	$form->{order_list}->node_set_row_data($node, \$data);

	my $query_paperwork = $form->{dbh}->prepare("select req_messages.subject,
	message from req_messages, req_requests, ccdb_paperwork_types where req_requests.request
	= req_messages.request and number = ? and (req_messages.subject
	like '[CSL #%] ' || type or req_messages.subject = type)");
	$query_paperwork->execute($row->[0]);

	while (my @row = $query_paperwork->fetchrow)
	{
	    my ($subject, $id) = @row;
	    $subject =~ s/\[CSL \#\d+\]\s//;
	    my $child = $form->{order_list}->insert_node($node, undef,
							 ['', $subject, '', '', '', ''], 0, undef,
							 undef, undef, undef, 1, 0);
	    my $data = $id;
	    $form->{order_list}->node_set_row_data($child, \$data);

	    $form->{order_list}->expand($child)
		if $expanded{$id};
	    $form->{order_list}->select($child)
		if $selected eq $id;
	}

	$form->{order_list}->expand($node)
	    if $expanded{$row->[0]};
	$form->{order_list}->select($node)
	    if $selected eq $row->[0];
    }
    $form->{order_list}->thaw;

    my $i = 0;
    while (my $node = $form->{order_list}->node_nth($i))
    {
	$i++;
	my $data = $form->{order_list}->node_get_row_data($node);
	next unless $top eq $$data;

	$form->{order_list}->node_moveto($node, 0, 0, 0);
	last;
    }
}

sub get_current_order
{
    my ($form) = @_;

    return $form->{last_order} unless $form->{order_list}->selection;

    my $val =
    $form->{order_list}->node_get_row_data($form->{order_list}->selection);

    if ($$val =~ /\D/)
    { 
	$val =
    $form->{order_list}->node_get_row_data($form->{order_list}->selection->row->parent);
    }
    $form->{last_order} = $$val;
    return $$val;
}

# DBI error handling helpers
sub begin
{
    my ($dbh) = @_;
    
    $dbh->{_dbi_error} = 0;
    {
        # In case we're already in a transaction
        local $dbh->{HandleError} = undef;
        $dbh->begin_work;
    }
}

sub commit
{
    my ($dbh) = @_;

    if ($dbh->{_dbi_error})
    {
        $dbh->rollback;
    }
    else
    {
        $dbh->commit;
    }

    return !$dbh->{_dbi_error};
}

# Print a handy stack trace for debugging
sub dbi_error
{
    my ($errstr, $dbh, $ret) = @_;

    # Get the stack trace
    my $trace;
    my $level = 1;
    while (my @caller = caller($level))
    {
        last if $caller[0] eq "main";
        $trace .= " " x ($level*2) . "$caller[3], line $caller[2]\n";
        $level++;
    }

    # Format it
    $errstr = autoformat $errstr, { all => 1 };

    # Display it
    # NEED #
    # MessageDialog support in Gtk
    my $box = Gnome::MessageBox->new("Database error:\n$errstr\nCalled at:\n$trace", "error", "Ok")->run;
    $box->show;

    $dbh->{_dbi_error} = 1;
}





#==============================================================================
#=== This is the 'Subfile_selection' class                              
#==============================================================================
package Subfile_selection;
require 5.000; use strict 'vars', 'refs', 'subs';
# UI class 'Subfile_selection' (version 0.01)
# 
# Copyright (c) Date Thu Aug 22 12:40:43 CDT 2002
# Author Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
# Unspecified copying policy, please contact the author\n#  Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
#==============================================================================
# This perl source file was automatically generated by 
# Glade::PerlGenerate version 0.56 - Wed Apr 19 02:28:58 BST 2000
# Copyright (c) Author Dermot Musgrove <dermot.musgrove\@virgin.net>
#
# from Glade file /afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/ccdb.glade
# Thu Aug 22 12:40:43 CDT 2002
#==============================================================================

BEGIN {
    use vars qw( 
                 @ISA
                 %fields
                 $VERSION
             );
    # Existing signal handler modules
    use src::CCDB;
    # We need the Gnome bindings as well
    use Gnome;
    # Uncomment the line below to enable gettext checking
#    use Glade::PerlSource;
    # Tell interpreter who we are inheriting from
    @ISA     = qw( file_selection );
    # Uncomment the line below to enable gettext checking
#    @ISA      = qw( file_selection Glade::PerlSource );
    $VERSION = '0.01';
    # Inherit the AUTOLOAD dynamic methods from file_selection
    *AUTOLOAD = \&file_selection::AUTOLOAD;
} # End of sub BEGIN

%fields = (
# Insert any extra data access methods that you want to add to 
#   our inherited super-constructor (or overload)
    USERDATA    => undef,
    VERSION     => '0.01',
);

sub DESTROY {
    # This sub will be called on object destruction
} # End of sub DESTROY

#==============================================================================
#=== Below are the overloaded class constructors
#==============================================================================
sub new {
    my $that  = shift;
    # Allow indirect constructor so that we can call eg. 
    #   $window1 = BusFrame->new; $window2 = $window1->new;
    my $class = ref($that) || $that;

    # Call our super-class constructor to get an object and reconsecrate it
    my $self = bless $that->SUPER::new(), $class;

    # Add our own data access methods to the inherited constructor
    my($element);
    foreach $element (keys %fields) {
        $self->{_permitted_fields}->{$element} = $fields{$element};
    }
    @{$self}{keys %fields} = values %fields;
    return $self;
} # End of sub new

sub run {
    my ($class) = @_;
    return unless Gtk->main_level == 1;
    Gnome->init('CCDB', '0.01');
    # Uncomment the line below to enable gettext checking
#    $class->check_gettext_strings;
    my $window = $class->new;
    # Insert your subclass user data key/value pairs 
    $window->USERDATA({
#        'Key1'   => 'Value1',
#        'Key2'   => 'Value2',
#        'Key3'   => 'Value3',
    });
    $window->TOPLEVEL->show;
#    my $window2 = $window->new;
#    $window2->TOPLEVEL->show;
    Gtk->main;
    # Uncomment the line below to enable gettext checking
#    $window->write_gettext_strings("__", '/afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/src/CCDB.pot');

    my $file = $window->{FORM}{file_selection}->get_filename;
    $window->{FORM}{file_selection}->destroy;

    return $file;
} # End of sub run
#===============================================================================
#=== Below are (overloaded) default signal handlers for 'file_selection' class 
#===============================================================================
sub about_Form {
    my ($class) = @_;
    my $gtkversion = 
        Gtk->major_version.".".
        Gtk->minor_version.".".
        Gtk->micro_version;
    my $name = $0;
    #
    # Create a Gnome::About '$ab'
    my $ab = new Gnome::About(
        "SubCCDB", 
        "0.01", 
        _("Copyright")." Thu Aug 22 12:40:43 CDT 2002", 
        "Nathan Mueller <nmueller\@newton.cs.wisc.edu>", 
        _("No description")."\n".
        "Gtk ".     _("version").": $gtkversion\n".
        "Gtk-Perl "._("version").": $Gtk::VERSION\n".
        _("run from file").": $name\n".
        "# Unspecified copying policy, please contact the author\n# ", 
        "$Glade::PerlRun::pixmaps_directory/glade2perl_logo.xpm", 
    );
    $ab->set_title(_("About")." SubCCDB" );
    $ab->position('mouse' );
    $ab->set_policy(1, 1, 0 );
    $ab->set_modal(1 );
    $ab->show;
} # End of sub about_Form

sub destroy_Form {
    my ($class, $data, $object, $instance) = @_;
    Gtk->main_quit; 
} # End of sub destroy_Form

sub toplevel_hide    { shift->get_toplevel->hide    }
sub toplevel_close   { shift->get_toplevel->close   }
sub toplevel_destroy { shift->get_toplevel->destroy }


#==============================================================================
#=== Below are (overloaded) signal handlers for 'file_selection' class 
#==============================================================================
sub on_cancel_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_cancel_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    $form->{file_selection}->set_filename("");
    Gtk->main_quit;
} # End of sub on_cancel_clicked

sub on_ok_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_ok_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    Gtk->main_quit;
} # End of sub on_ok_clicked










#==============================================================================
#=== This is the 'Subpart_window' class                              
#==============================================================================
package Subpart_window;
require 5.000; use strict 'vars', 'refs', 'subs';
# UI class 'Subpart_window' (version 0.01)
# 
# Copyright (c) Date Thu Aug 22 12:40:43 CDT 2002
# Author Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
# Unspecified copying policy, please contact the author\n#  Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
#==============================================================================
# This perl source file was automatically generated by 
# Glade::PerlGenerate version 0.56 - Wed Apr 19 02:28:58 BST 2000
# Copyright (c) Author Dermot Musgrove <dermot.musgrove\@virgin.net>
#
# from Glade file /afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/ccdb.glade
# Thu Aug 22 12:40:43 CDT 2002
#==============================================================================

BEGIN {
    use vars qw( 
                 @ISA
                 %fields
                 $VERSION
             );
    # Existing signal handler modules
    use src::CCDB;
    # We need the Gnome bindings as well
    use Gnome;
    # Uncomment the line below to enable gettext checking
#    use Glade::PerlSource;
    # Tell interpreter who we are inheriting from
    @ISA     = qw( part_window );
    # Uncomment the line below to enable gettext checking
#    @ISA      = qw( part_window Glade::PerlSource );
    $VERSION = '0.01';
    # Inherit the AUTOLOAD dynamic methods from part_window
    *AUTOLOAD = \&part_window::AUTOLOAD;
} # End of sub BEGIN

%fields = (
# Insert any extra data access methods that you want to add to 
#   our inherited super-constructor (or overload)
    USERDATA    => undef,
    VERSION     => '0.01',
);

sub DESTROY {
    # This sub will be called on object destruction
} # End of sub DESTROY

#==============================================================================
#=== Below are the overloaded class constructors
#==============================================================================
sub new {
    my $that  = shift;
    # Allow indirect constructor so that we can call eg. 
    #   $window1 = BusFrame->new; $window2 = $window1->new;
    my $class = ref($that) || $that;

    # Call our super-class constructor to get an object and reconsecrate it
    my $self = bless $that->SUPER::new(), $class;

    # Add our own data access methods to the inherited constructor
    my($element);
    foreach $element (keys %fields) {
        $self->{_permitted_fields}->{$element} = $fields{$element};
    }
    @{$self}{keys %fields} = values %fields;
    return $self;
} # End of sub new

sub run {
    my ($class, $part, $cost, $quan) = @_;
    return unless Gtk->main_level == 1;
    Gnome->init('CCDB', '0.01');
    # Uncomment the line below to enable gettext checking
#    $class->check_gettext_strings;
    my $window = $class->new;
    # Insert your subclass user data key/value pairs 
    $window->USERDATA({
#        'Key1'   => 'Value1',
#        'Key2'   => 'Value2',
#        'Key3'   => 'Value3',
    });
    $window->TOPLEVEL->show;
#    my $window2 = $window->new;
#    $window2->TOPLEVEL->show;
    
    $window->{FORM}{part_desc}->set_text($part);
    $window->{FORM}{cost}->set_text($cost);
    $window->{FORM}{quantity}->set_text($quan);

    Gtk->main;
    # Uncomment the line below to enable gettext checking
#    $window->write_gettext_strings("__", '/afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/src/CCDB.pot');
    my $part = $window->{FORM}{part_desc}->get_text;
    (my $cost = $window->{FORM}{cost}->get_text) =~ s/\$//;
    my $quan = $window->{FORM}{quantity}->get_text;
    $window->{FORM}{part_window}->destroy;
    return ($part, $cost, $quan);
} # End of sub run
#===============================================================================
#=== Below are (overloaded) default signal handlers for 'part_window' class 
#===============================================================================
sub about_Form {
    my ($class) = @_;
    my $gtkversion = 
        Gtk->major_version.".".
        Gtk->minor_version.".".
        Gtk->micro_version;
    my $name = $0;
    #
    # Create a Gnome::About '$ab'
    my $ab = new Gnome::About(
        "SubCCDB", 
        "0.01", 
        _("Copyright")." Thu Aug 22 12:40:43 CDT 2002", 
        "Nathan Mueller <nmueller\@newton.cs.wisc.edu>", 
        _("No description")."\n".
        "Gtk ".     _("version").": $gtkversion\n".
        "Gtk-Perl "._("version").": $Gtk::VERSION\n".
        _("run from file").": $name\n".
        "# Unspecified copying policy, please contact the author\n# ", 
        "$Glade::PerlRun::pixmaps_directory/glade2perl_logo.xpm", 
    );
    $ab->set_title(_("About")." SubCCDB" );
    $ab->position('mouse' );
    $ab->set_policy(1, 1, 0 );
    $ab->set_modal(1 );
    $ab->show;
} # End of sub about_Form

sub destroy_Form {
    my ($class, $data, $object, $instance) = @_;
    Gtk->main_quit; 
} # End of sub destroy_Form

sub toplevel_hide    { shift->get_toplevel->hide    }
sub toplevel_close   { shift->get_toplevel->close   }
sub toplevel_destroy { shift->get_toplevel->destroy }


#==============================================================================
#=== Below are (overloaded) signal handlers for 'part_window' class 
#==============================================================================
sub on_cancel_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_cancel_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    $form->{part_desc}->set_text("");
    $form->{cost}->set_text("");
    $form->{quantity}->set_text("");

    Gtk->main_quit;
} # End of sub on_cancel_clicked

sub on_ok_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_ok_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    Gtk->main_quit;
} # End of sub on_ok_clicked










#==============================================================================
#=== This is the 'Subconvert_req_window' class                              
#==============================================================================
package Subconvert_req_window;
require 5.000; use strict 'vars', 'refs', 'subs';
use IO::File;
# UI class 'Subconvert_req_window' (version 0.01)
# 
# Copyright (c) Date Thu Aug 22 12:40:43 CDT 2002
# Author Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
# Unspecified copying policy, please contact the author\n#  Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
#==============================================================================
# This perl source file was automatically generated by 
# Glade::PerlGenerate version 0.56 - Wed Apr 19 02:28:58 BST 2000
# Copyright (c) Author Dermot Musgrove <dermot.musgrove\@virgin.net>
#
# from Glade file /afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/ccdb.glade
# Thu Aug 22 12:40:43 CDT 2002
#==============================================================================

BEGIN {
    use vars qw( 
                 @ISA
                 %fields
                 $VERSION
             );
    # Existing signal handler modules
    use src::CCDB;
    # We need the Gnome bindings as well
    use Gnome;
    # Uncomment the line below to enable gettext checking
#    use Glade::PerlSource;
    # Tell interpreter who we are inheriting from
    @ISA     = qw( convert_req_window );
    # Uncomment the line below to enable gettext checking
#    @ISA      = qw( convert_req_window Glade::PerlSource );
    $VERSION = '0.01';
    # Inherit the AUTOLOAD dynamic methods from convert_req_window
    *AUTOLOAD = \&convert_req_window::AUTOLOAD;
} # End of sub BEGIN

%fields = (
# Insert any extra data access methods that you want to add to 
#   our inherited super-constructor (or overload)
    USERDATA    => undef,
    VERSION     => '0.01',
);

sub DESTROY {
    # This sub will be called on object destruction
} # End of sub DESTROY

#==============================================================================
#=== Below are the overloaded class constructors
#==============================================================================
sub new {
    my $that  = shift;
    # Allow indirect constructor so that we can call eg. 
    #   $window1 = BusFrame->new; $window2 = $window1->new;
    my $class = ref($that) || $that;

    # Call our super-class constructor to get an object and reconsecrate it
    my $self = bless $that->SUPER::new(), $class;

    # Add our own data access methods to the inherited constructor
    my($element);
    foreach $element (keys %fields) {
        $self->{_permitted_fields}->{$element} = $fields{$element};
    }
    @{$self}{keys %fields} = values %fields;
    return $self;
} # End of sub new

sub run {
    my ($class) = @_;
    return unless Gtk->main_level == 1;
    Gnome->init('CCDB', '0.01');
    # Uncomment the line below to enable gettext checking
#    $class->check_gettext_strings;
    my $window = $class->new;
    # Insert your subclass user data key/value pairs 
    $window->USERDATA({
#        'Key1'   => 'Value1',
#        'Key2'   => 'Value2',
#        'Key3'   => 'Value3',
    });
    $window->TOPLEVEL->show;

    # Fill in list of staff
    my $file = new IO::File "/s/lab/lib/faclist";
    my @people = sort map { s/\s*\|.*//; $_ } grep /./, <$file>;
    $file->close;
    unshift @people, "lab";
    chomp(@people);
    map { $_ = Gtk::ListItem->new($_); $_->show } @people;
    $window->{FORM}{user}->list->append_items(@people);

    # Default purchasing card
    if (getpwuid($<) eq "dparter")
    {
	$window->{FORM}->{parter_card}->set_active(1);
    }

#    my $window2 = $window->new;
#    $window2->TOPLEVEL->show;
    Gtk->main;
    # Uncomment the line below to enable gettext checking
#    $window->write_gettext_strings("__",
#    '/afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/src/CCDB.pot');
    my $number = $window->{FORM}{req_number}->get_text;
    my $vendor = $window->{FORM}{vendor}->get_text;
    my $subject = $window->{FORM}{subject}->get_text;
    my $user = $window->{FORM}{user}->entry->get_text;
    my $card;
    if ($window->{FORM}->{beebe_card}->get_active)
    {
	$card = "beebe";
    }
    else
    {
	$card = "parter";
    }
    $window->{FORM}{convert_req_window}->destroy;
    return ($number, $subject, $vendor, $card, $user);
} # End of sub run
#===============================================================================
#=== Below are (overloaded) default signal handlers for 'convert_req_window' class 
#===============================================================================
sub about_Form {
    my ($class) = @_;
    my $gtkversion = 
        Gtk->major_version.".".
        Gtk->minor_version.".".
        Gtk->micro_version;
    my $name = $0;
    #
    # Create a Gnome::About '$ab'
    my $ab = new Gnome::About(
        "SubCCDB", 
        "0.01", 
        _("Copyright")." Thu Aug 22 12:40:43 CDT 2002", 
        "Nathan Mueller <nmueller\@newton.cs.wisc.edu>", 
        _("No description")."\n".
        "Gtk ".     _("version").": $gtkversion\n".
        "Gtk-Perl "._("version").": $Gtk::VERSION\n".
        _("run from file").": $name\n".
        "# Unspecified copying policy, please contact the author\n# ", 
        "$Glade::PerlRun::pixmaps_directory/glade2perl_logo.xpm", 
    );
    $ab->set_title(_("About")." SubCCDB" );
    $ab->position('mouse' );
    $ab->set_policy(1, 1, 0 );
    $ab->set_modal(1 );
    $ab->show;
} # End of sub about_Form

sub destroy_Form {
    my ($class, $data, $object, $instance) = @_;
    Gtk->main_quit; 
} # End of sub destroy_Form

sub toplevel_hide    { shift->get_toplevel->hide    }
sub toplevel_close   { shift->get_toplevel->close   }
sub toplevel_destroy { shift->get_toplevel->destroy }


#==============================================================================
#=== Below are (overloaded) signal handlers for 'convert_req_window' class 
#==============================================================================
sub on_button22_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_button22_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    $form->{req_number}->set_text("");
    $form->{vendor}->set_text("");
    $form->{subject}->set_text("");
    $form->{user}->entry->set_text("");
    Gtk->main_quit;
} # End of sub on_button22_clicked

sub on_ok_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_ok_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};
    
    Gtk->main_quit;
} # End of sub on_ok_clicked




#==============================================================================
#=== This is the 'Subnumber_window' class                              
#==============================================================================
package Subnumber_window;
require 5.000; use strict 'vars', 'refs', 'subs';
# UI class 'Subnumber_window' (version 0.01)
# 
# Copyright (c) Date Tue Sep 10 14:40:04 CDT 2002
# Author Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
# Unspecified copying policy, please contact the author\n#  Nathan Mueller <nmueller\@newton.cs.wisc.edu>
#
#==============================================================================
# This perl source file was automatically generated by 
# Glade::PerlGenerate version 0.56 - Wed Apr 19 02:28:58 BST 2000
# Copyright (c) Author Dermot Musgrove <dermot.musgrove\@virgin.net>
#
# from Glade file /afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/ccdb.glade
# Tue Sep 10 14:40:04 CDT 2002
#==============================================================================

BEGIN {
    use vars qw( 
                 @ISA
                 %fields
                 $VERSION
             );
    # Existing signal handler modules
    use src::CCDB;
    # We need the Gnome bindings as well
    use Gnome;
    # Uncomment the line below to enable gettext checking
#    use Glade::PerlSource;
    # Tell interpreter who we are inheriting from
    @ISA     = qw( number_window );
    # Uncomment the line below to enable gettext checking
#    @ISA      = qw( convert_req_window Glade::PerlSource );
    $VERSION = '0.01';
    # Inherit the AUTOLOAD dynamic methods from convert_req_window
    *AUTOLOAD = \&number_window::AUTOLOAD;
} # End of sub BEGIN

%fields = (
# Insert any extra data access methods that you want to add to 
#   our inherited super-constructor (or overload)
    USERDATA    => undef,
    VERSION     => '0.01',
);

sub DESTROY {
    # This sub will be called on object destruction
} # End of sub DESTROY

#==============================================================================
#=== Below are the overloaded class constructors
#==============================================================================
sub new {
    my $that  = shift;
    # Allow indirect constructor so that we can call eg. 
    #   $window1 = BusFrame->new; $window2 = $window1->new;
    my $class = ref($that) || $that;

    # Call our super-class constructor to get an object and reconsecrate it
    my $self = bless $that->SUPER::new(), $class;

    # Add our own data access methods to the inherited constructor
    my($element);
    foreach $element (keys %fields) {
        $self->{_permitted_fields}->{$element} = $fields{$element};
    }
    @{$self}{keys %fields} = values %fields;
    return $self;
} # End of sub new

sub run {
    my ($class, $val, $title) = @_;
    return unless Gtk->main_level == 1;
    Gnome->init('CCDB', '0.01');
    # Uncomment the line below to enable gettext checking
#    $class->check_gettext_strings;
    my $window = $class->new;
    # Insert your subclass user data key/value pairs 
    $window->USERDATA({
#        'Key1'   => 'Value1',
#        'Key2'   => 'Value2',
#        'Key3'   => 'Value3',
    });
    $window->TOPLEVEL->show;
    $window->{FORM}{num}->set_text($val);
    $window->{FORM}{number_window}->title($title);
    $window->{FORM}{label52}->set_text("$title:");

#    my $window2 = $window->new;
#    $window2->TOPLEVEL->show;
    Gtk->main;
    # Uncomment the line below to enable gettext checking
#    $window->write_gettext_strings("__",
#    '/afs/cs.wisc.edu/u/n/m/nmueller/work/ccdb/src/CCDB.pot');
    my $value = $window->{FORM}{num}->get_text;
    $window->{FORM}{number_window}->destroy;
    return $value;
} # End of sub run

#===============================================================================
#=== Below are the default signal handlers for 'Subnumber_window' class
#===============================================================================
sub about_Form {
    my ($class) = @_;
    my $gtkversion = 
        Gtk->major_version.".".
        Gtk->minor_version.".".
        Gtk->micro_version;
    my $name = $0;
    #
    # Create a Gnome::About '$ab'
    my $ab = new Gnome::About(
        "CCDB", 
        "0.01", 
        _("Copyright")." Tue Sep 10 14:40:04 CDT 2002", 
        "Nathan Mueller <nmueller\@newton.cs.wisc.edu>", 
        _("No description")."\n".
        "Gtk ".     _("version").": $gtkversion\n".
        "Gtk-Perl "._("version").": $Gtk::VERSION\n".
        _("run from file").": $name\n".
        "# Unspecified copying policy, please contact the author\n# ", 
        "$Glade::PerlRun::pixmaps_directory/glade2perl_logo.xpm", 
    );
    $ab->set_title(_("About")." CCDB" );
    $ab->position('mouse' );
    $ab->set_policy(1, 1, 0 );
    $ab->set_modal(1 );
    $ab->show;
} # End of sub about_Form

sub destroy_Form {
    my ($class, $data, $object, $instance) = @_;
    Gtk->main_quit; 
} # End of sub destroy_Form

sub toplevel_hide    { shift->get_toplevel->hide    }
sub toplevel_close   { shift->get_toplevel->close   }
sub toplevel_destroy { shift->get_toplevel->destroy }


#==============================================================================
#=== Below are the signal handlers for 'Subnumber_window' class 
#==============================================================================
sub on_cancel_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_cancel_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};

    $form->{num}->set_text("");
    Gtk->main_quit;

} # End of sub on_cancel_clicked

sub on_ok_clicked {
    my ($class, $data, $object, $instance, $event) = @_;
    my $me = __PACKAGE__."->on_ok_clicked";
    # Get ref to hash of all widgets on our form
    my $form = $__PACKAGE__::all_forms->{$instance};
    
    Gtk->main_quit;

} # End of sub on_ok_clicked







1;

__END__

#===============================================================================
#==== Documentation
#===============================================================================
=pod

=head1 NAME

SubCCDB - version 0.01 Thu Aug 22 12:40:43 CDT 2002

No description

=head1 SYNOPSIS

 use SubCCDB;

 if ($we_want_to_subclass_this_class) {
   # Inherit the AUTOLOAD dynamic methods from Submain_window
   *AUTOLOAD = \&Submain_window::AUTOLOAD;

   # Tell interpreter who we are inheriting from
   use vars qw( @ISA ); @ISA = qw( Submain_window );
 }
 
 To construct the window object and show it call
 
 Gtk->init;
 my $window = Submain_window->new;
 $window->TOPLEVEL->show;
 Gtk->main;
 
 OR use the shorthand for the above calls
 
 Submain_window->run;

=head1 DESCRIPTION

Unfortunately, the author has not yet written any documentation :-(

=head1 AUTHOR

Nathan Mueller <nmueller\@newton.cs.wisc.edu>

=cut
