NAME

GT::SQL::Admin - instant admin for any sql table.


SYNOPSIS

    my $cgi   = new GT::CGI;
    my $db    = new GT::SQL '/path/to/def';
    my $admin = new GT::SQL::Admin;
    if ($admin->for_me($cgi)) {
        $admin->process ( db => $db, cgi => $cgi );
    }


DESCRIPTION

GT::SQL::Admin provides an easy way to build a table/relation management application. It provides all the HTML and code to easily:

    1. Add records
    2. Delete records
    3. Modify records
    4. Search records
    5. Add columns
    6. Drop columns
    7. Alter table properties
    8. Import data
    9. Export data

all in about 6 lines of code.

Usage

To use GT::SQL::Admin you need to pass in an existing the GT::SQL manpage object, and a the GT::CGI manpage object.

In it's simplest usage, you can simply call:

    my $admin = new GT::SQL::Admin;
    $admin->process ( db => $db, cgi => $cgi );

and the admin module will figure out what was requested and display the appropriate screen. There is a $admin->for_me method that will look to see if the cgi object contains something for the admin to do, returning 1 if yes, 0 otherwise. You would then do:

    my $cgi = new GT::CGI;
    my $admin = new GT::SQL::Admin;
    if ($admin->for_me($cgi)) {
        $admin->process ( db => $db, cgi => $cgi );
    }

You can also call any of the methods individually. You can create an add form like:

    $admin->add_form;

and it will be printed to STDOUT.

To change the look of a page, you can pass in strings or code refs to display any of the following items:

    start_html
    header
    start_form
    end_form
    footer
    end_html

and the admin will use your html/code when displaying. You can also pass in to process:

        record       => 'MyObject'

and the admin will use that string when displaying titles like 'Add MyObject'. If you don't specify, it will default to the name of the table.

Subclassing the admin

You can enhance the functionality of an admin quite easily. By default GT::SQL::Admin expects to find a GT::SQL object, a GT::CGI object, and uses internally a GT::SQL::Display::HTML object for any form/record html generation.

Alternatively, you can subclass one or more of the above and use your own libraries. For instance, if you wanted to expand the form generation, you could subclass the GT::SQL::Display::HTML object and override the display() and form() method with your own.

The admin will pass in a 'mode' to both display and form that will tell you what it is using the form for. This can be one of:

    search_form
    search_results
    add_form
    add_success
    delete_search_form
    delete_search_results
    download_file
    modify_search_form
    modify_search_results
    modify_form
    modify_success
    modify_multi_search_results
    modify_multi_results_norec
    modify_multi_result_changed
    modify_multi_results_err

There are also several options that can be passed in. See the the GT::SQL::Display::HTML manpage module for more information.

Also be sure to read about subclassing in the GT::SQL manpage.


COPYRIGHT

Copyright (c) 2004 Gossamer Threads Inc. All Rights Reserved. http://www.gossamer-threads.com/


VERSION

Revision: $Id: Admin.pm,v 1.146 2005/03/15 00:35:29 brewt Exp $