Commit 5a1c9ef7 authored by Keith Jolley's avatar Keith Jolley
Browse files

Source formatting.

parent c0d1089e
#Written by Keith Jolley
#Copyright (c) 2012, University of Oxford
#Copyright (c) 2012-2015, University of Oxford
#E-mail: keith.jolley@zoo.ox.ac.uk
#
#This file is part of Bacterial Isolate Genome Sequence Database (BIGSdb).
......@@ -38,7 +38,7 @@ sub print_content {
my $q = $self->{'cgi'};
my $table = $q->param('table');
if ( !$self->{'datastore'}->is_table($table) ) {
print "<div class=\"box\" id=\"statusbad\"><p>Table $table does not exist!</p></div>\n";
say qq(<div class="box" id="statusbad"><p>Table $table does not exist!</p></div>);
return;
} elsif (
none {
......@@ -47,13 +47,13 @@ sub print_content {
qw (user_group_members locus_curators scheme_curators)
)
{
print "<div class=\"box\" id=\"statusbad\"><p>Invalid table selected!</p></div>\n";
say qq(<div class="box" id="statusbad"><p>Invalid table selected!</p></div>);
return;
}
my $type = $self->get_record_name($table) // 'record';
print "<h1>Batch update $type" . "s </h1>\n";
say "<h1>Batch update $type" . "s </h1>";
if ( !$self->can_modify_table($table) ) {
print "<div class=\"box\" id=\"statusbad\"><p>Your user account does not have permission to modify this table.<p></div>\n";
say qq(<div class="box" id="statusbad"><p>Your user account does not have permission to modify this table.<p></div>);
return;
}
$self->_print_interface;
......@@ -61,26 +61,26 @@ sub print_content {
}
sub _print_interface {
my ($self) = @_;
my $q = $self->{'cgi'};
my $table = $q->param('table');
print "<div class=\"box\" id=\"queryform\">\n";
my ($self) = @_;
my $q = $self->{'cgi'};
my $table = $q->param('table');
my $user_id = $q->param('users_list');
if ( $user_id && BIGSdb::Utils::is_int($user_id) ) {
$self->_perform_action($table);
my $user_info = $self->{'datastore'}->get_user_info($user_id);
if ( !$user_info ) {
print "<p class=\"statusbad\">Invalid user selected.</p>\n</div>\n";
say qq(<div class="box" id="statusbad"><p>Invalid user selected.</p></div>);
return;
}
print "<b>User: $user_info->{'first_name'} $user_info->{'surname'}</b>\n";
print "<p>Select values to enable or disable and then click the appropriate arrow button.</p>\n";
say qq(<div class="box" id="queryform">);
say "<b>User: $user_info->{'first_name'} $user_info->{'surname'}</b>";
say "<p>Select values to enable or disable and then click the appropriate arrow button.</p>";
my $table_data = $self->_get_table_data($table);
print "<fieldset><legend>Select $table_data->{'plural'}</legend>\n";
say "<fieldset><legend>Select $table_data->{'plural'}</legend>";
my $set_clause = '';
my $set_id = $self->get_set_id;
if ($set_id) {
if ($set_id) {
if ( $table eq 'locus_curators' ) {
#make sure 'id IN' has a space before it - used in the substitution a few lines on (also matches scheme_id otherwise).
......@@ -91,20 +91,23 @@ sub _print_interface {
}
}
my $available = $self->{'datastore'}->run_list_query(
"SELECT id FROM $table_data->{'parent'} WHERE id NOT IN (SELECT $table_data->{'foreign'} FROM $table WHERE $table_data->{'user_field'}=?) $set_clause ORDER BY $table_data->{'order'}",
"SELECT id FROM $table_data->{'parent'} WHERE id NOT IN (SELECT $table_data->{'foreign'} FROM $table WHERE "
. "$table_data->{'user_field'}=?) $set_clause ORDER BY $table_data->{'order'}",
$user_id
);
push @$available, '' if !@$available;
$set_clause =~ s/id IN/$table_data->{'foreign'} IN/;
my $selected = $self->{'datastore'}->run_list_query(
"SELECT $table_data->{'foreign'} FROM $table LEFT JOIN $table_data->{'parent'} ON $table_data->{'foreign'} = $table_data->{'id'} WHERE $table_data->{'user_field'}=? $set_clause ORDER BY $table_data->{'parent'}.$table_data->{'order'}",
"SELECT $table_data->{'foreign'} FROM $table LEFT JOIN $table_data->{'parent'} ON $table_data->{'foreign'} = "
. "$table_data->{'id'} WHERE $table_data->{'user_field'}=? $set_clause ORDER BY $table_data->{'parent'}."
. "$table_data->{'order'}",
$user_id
);
push @$selected, '' if !@$selected;
my $labels = $self->_get_labels($table);
print $q->start_form;
print "<table><tr><th>Available</th><td></td><th>Selected</th></tr>\n<tr><td>";
print $q->popup_menu(
say $q->start_form;
say "<table><tr><th>Available</th><td></td><th>Selected</th></tr>\n<tr><td>";
say $q->popup_menu(
-name => 'available',
-id => 'available',
-values => $available,
......@@ -112,12 +115,12 @@ sub _print_interface {
-labels => $labels,
-style => 'min-width:10em; min-height:15em'
);
print "</td><td>\n";
print $q->submit( -name => 'add', -label => '>', -class => 'submit' );
print "<br />\n";
print $q->submit( -name => 'remove', -label => '<', -class => 'submit' );
print "</td><td>\n";
print $q->popup_menu(
say "</td><td>";
say $q->submit( -name => 'add', -label => '>', -class => 'submit' );
say "<br />";
say $q->submit( -name => 'remove', -label => '<', -class => 'submit' );
say "</td><td>";
say $q->popup_menu(
-name => 'selected',
-id => 'selected',
-values => $selected,
......@@ -125,31 +128,32 @@ sub _print_interface {
-labels => $labels,
-style => 'min-width:10em; min-height:15em'
);
print "</td></tr>\n";
print "<tr><td style=\"text-align:center\"><input type=\"button\" onclick='listbox_selectall(\"available\",true)'"
. " value=\"All\" style=\"margin-top:1em\" class=\"smallbutton\" />\n";
print "<input type=\"button\" onclick='listbox_selectall(\"available\",false)' value=\"None\" "
. "style=\"margin-top:1em\" class=\"smallbutton\" /></td><td></td>\n";
print "<td style=\"text-align:center\"><input type=\"button\" onclick='listbox_selectall(\"selected\",true)' "
. "value=\"All\" style=\"margin-top:1em\" class=\"smallbutton\" />\n";
print "<input type=\"button\" onclick='listbox_selectall(\"selected\",false)' value=\"None\" "
. "style=\"margin-top:1em\" class=\"smallbutton\" />\n";
print "</td></tr>\n";
say "</td></tr>";
say qq(<tr><td style="text-align:center"><input type="button" onclick='listbox_selectall("available",true)' )
. qq(value="All" style="margin-top:1em" class="smallbutton" />);
say qq(<input type="button" onclick='listbox_selectall("available",false)' value="None" )
. qq(style="margin-top:1em" class="smallbutton" /></td><td></td>);
say qq(<td style="text-align:center"><input type="button" onclick='listbox_selectall("selected",true)' )
. qq(value="All" style="margin-top:1em" class="smallbutton" />);
say qq(<input type="button" onclick='listbox_selectall("selected",false)' value="None" )
. qq(style="margin-top:1em" class="smallbutton" />);
say "</td></tr>";
if ( $table eq 'locus_curators' ) {
print "<tr><td colspan=\"3\">\n";
print $q->checkbox( -name => 'hide_public', -label => 'Hide curator name from public view', -checked => 'checked' );
print "</td></tr>\n";
say qq(<tr><td colspan="3">);
say $q->checkbox( -name => 'hide_public', -label => 'Hide curator name from public view', -checked => 'checked' );
say "</td></tr>";
}
print "</table>\n";
print $q->hidden($_) foreach qw(db page table users_list);
print $q->end_form;
print "</fieldset>\n";
print "<p><a href=\"$self->{'system'}->{'script_name'}?db=$self->{'instance'}\">Back to main</a></p>\n";
say "</table>";
say $q->hidden($_) foreach qw(db page table users_list);
say $q->end_form;
say "</fieldset>";
say qq(<p><a href="$self->{'system'}->{'script_name'}?db=$self->{'instance'}">Back to main</a></p>);
} else {
print $self->_print_sender_form;
say qq(<div class="box" id="queryform">);
say $self->_print_user_form;
}
print "</div>\n";
say "</div>";
return;
}
......@@ -205,26 +209,27 @@ sub _perform_action {
return;
}
sub _print_sender_form {
sub _print_user_form {
my ($self) = @_;
my $q = $self->{'cgi'};
my $list = $self->{'datastore'}->run_query( "SELECT id,user_name,first_name,surname from users WHERE id>0 order by surname",
my $q = $self->{'cgi'};
my $list =
$self->{'datastore'}->run_query( "SELECT id,user_name,first_name,surname from users WHERE id>0 AND status != 'user' order by surname",
undef, { fetch => 'all_arrayref', slice => {} } );
my ( @users, %usernames );
foreach (@$list) {
push @users, $_->{'id'};
$usernames{ $_->{'id'} } = "$_->{'surname'}, $_->{'first_name'} ($_->{'user_name'})";
}
print "<fieldset><legend>Select user</legend>\n";
print "<p>The user status must also be <a href=\"$self->{'system'}->{'script_name'}?db=$self->{'instance'}&amp;"
. "page=tableQuery&amp;table=users\">set to curator</a> for permissions to work.</p>"
say "<fieldset><legend>Select user</legend>";
say qq(<p>The user status must also be <a href="$self->{'system'}->{'script_name'}?db=$self->{'instance'}&amp;)
. qq(page=tableQuery&amp;table=users">set to curator</a> for permissions to work.</p>)
if $q->param('table') =~ /_curators$/;
print $q->start_form;
print $self->get_filter( 'users', \@users, { class => 'display', labels => \%usernames } );
print $q->submit( -name => 'Select', -class => 'submit' );
print $q->hidden($_) foreach qw(db page table);
print $q->end_form;
print "</fieldset>\n";
say $q->start_form;
say $self->get_filter( 'users', \@users, { class => 'display', labels => \%usernames } );
say $q->submit( -name => 'Select', -class => 'submit' );
say $q->hidden($_) foreach qw(db page table);
say $q->end_form;
say "</fieldset>";
return;
}
......@@ -241,7 +246,8 @@ sub _get_table_data {
user_field => 'user_id'
);
} elsif ( $table eq 'locus_curators' ) {
%values = ( parent => 'loci', plural => 'loci', id => 'id', foreign => 'locus', order => 'id', user_field => 'curator_id' );
%values =
( parent => 'loci', plural => 'loci', id => 'id', foreign => 'locus', order => 'id', user_field => 'curator_id' );
} elsif ( $table eq 'scheme_curators' ) {
%values = (
parent => 'schemes',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment