<%doc>

 Advanced Database Operations Section.

</%doc>

<%attr>
title   => 'Advanced DB operations' 
section => 'Advanced'
</%attr>

<%args>
$showheader => 1
$sql        => undef
$action     => undef
$sql_name   => undef
$submit     => undef
$forget     => undef
$forget_name   => undef
$saved_queries => undef
</%args>

<%init>
my $user = $ui->get_current_user($r);
my @t;

my $hideheader;
if( !$showheader ) {
    $hideheader = 'style="display:none"';
}
</%init>

<%shared>
my $PAGE_ATTRIBUTE = "GENERIC_PAGE";
my $SECTION = "Advanced";
</%shared>

<%method .section_meta_data>
    <%doc>
        Returns the meta data used to generate this sections header in section1.mhtml
    </%doc>
    <%init>
        return {  
	    section => $SECTION,
	    page => 'generic/',
	    title => 'Advanced',
	    attribute => $PAGE_ATTRIBUTE,
	    sub_sections => [],
        };
    </%init>
</%method>


% my $manager = $ui->get_permission_manager($r);
% if ( $manager && $manager->can($user, "access_section", 'generic') ){

<div id="sectiontools" <% $hideheader %>>
<div class="container">
    <div class="containerhead">
        Advanced Database Operations
    </div>

    <div class="containerbody">

    <p>From the menus below, select the table you want to work with to either search, add or browse records.
%     map { push @t, $_ unless ($_->name =~ /_history/) } 
%           sort { $a->name cmp $b->name }  $ui->meta->get_tables;
%

    </div> <!-- close containerbody -->
</div> <!-- close container -->

    <p>
    <fieldset class="small">
        <legend>Browse</legend>
        <form action="browse.html" method="POST" name="browse_form">
            <select name="table" onChange="document.browse_form.submit()">
            <option>Select table</option>
%           foreach my $t ( @t ) {
                <option value="<% $t->name %>"><% $t->db_name %></option>
%           }
            </select>
        </form>
    </fieldset>
    </p>
    <p>
    <fieldset class="small">
        <legend>Search</legend>
        <form action="search_obj.html" method="POST" name="search_form">
            <input type="hidden" name="adv_search" value="1">
            <select name="table" onChange="document.search_form.submit()">
            <option>Select table</option>
%       foreach my $t ( @t ) {
                <option value="<% $t->name %>"><% $t->db_name %></option>
%       }
            </select>
        </form>
    </fieldset>
    </p>
<%doc>
We do not want operators to insert any records
</%doc>
% if ( $user && $user->getAttribute('USER_TYPE') eq 'Admin' ){
    <p>
    <fieldset class="small">
        <legend>Add</legend>
        <form action="edit.html" method="POST" name="add_form">
            <select name="table" onChange="document.add_form.submit()">
            <option>Select table</option>
%       foreach my $t ( @t ) {
                <option value="<% $t->name %>"><% $t->db_name %></option>
%       }
            </select>
        </form>
    </fieldset>
    </p>
% }

<%doc>
Only Administrators should have access to the direct SQL functionality.
</%doc>
% if ( $user && $user->getAttribute('USER_TYPE') eq 'Admin' ){
  <& /generic/raw_sql.html, sql => $sql, action => $action, sql_name => $sql_name, submit => $submit, forget => $forget, forget_name => $forget_name, saved_queries => $saved_queries  &>
% }

</div> <!-- close sectiontools -->

% }

%if ( $m->fetch_next ){
%    $m->call_next();
%}

