Skip to content

Commit

Permalink
[11/30] Patron Card Creator batch editor interface and code
Browse files Browse the repository at this point in the history
  • Loading branch information
cnighswonger committed Jan 11, 2010
1 parent 80d2f5b commit 666c70d
Show file tree
Hide file tree
Showing 3 changed files with 272 additions and 0 deletions.
47 changes: 47 additions & 0 deletions C4/Patroncards/Batch.pm
@@ -0,0 +1,47 @@
package C4::Patroncards::Batch;

use strict;
use warnings;

use base qw(C4::Creators::Batch);

use autouse 'Data::Dumper' => qw(Dumper);

BEGIN {
use version; our $VERSION = qv('1.0.0_1');
}

__PACKAGE__ =~ m/^C4::(.+)::.+$/;
my $me = $1;

sub new {
my $self = shift;
push @_, "creator", $me;
return $self->SUPER::new(@_);
}

sub save {
my $self = shift;
push @_, "creator", $me;
return $self->SUPER::save(@_);
}

sub retrieve {
my $self = shift;
push @_, "creator", $me;
return $self->SUPER::retrieve(@_);
}

sub delete {
if (ref($_[0])) {
my $self = shift; # check to see if this is a method call
push @_, "creator", $me;
return $self->SUPER::delete(@_);
}
else {
push @_, "creator", $me;
return __PACKAGE__->SUPER::delete(@_); # XXX: is this too hackish?
}
}

1;
@@ -0,0 +1,89 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
<title>Koha &rsaquo; Tools &rsaquo; Labels &rsaquo; Manage Label Batches</title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<!-- TMPL_INCLUDE NAME="greybox.inc" -->
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
$("#cancel").empty();
buildButtons();
});
function buildButtons() {
var cancelButton = new YAHOO.widget.Button({
type: "link",
href: "/cgi-bin/koha/patroncards/manage.pl?card_element=batch",
label: _("Cancel"),
id: "cancel",
container: "cancel",
});
};
</script>
</head>
<body>
<!-- TMPL_INCLUDE NAME="header.inc" -->
<!-- TMPL_INCLUDE NAME="cat-search.inc" -->
<div id="breadcrumbs">
<a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
<a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
<a href="/cgi-bin/koha/patroncards/home.pl">Patroncards Home</a> &rsaquo;
<a href="/cgi-bin/koha/patroncards/manage.pl?card_element=batch">Manage Patroncards Batches</a> &rsaquo;
Manage Batch Number <!-- TMPL_VAR NAME="batch_id" -->
</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<!-- TMPL_INCLUDE NAME="patroncards-batches-toolbar.inc" -->
<!-- TMPL_INCLUDE NAME="error-messages.inc" -->
<div class="yui-g">
<div class="yui-u first" id="manage-patroncard-batches">
<div class="hint">Current Branch: <!-- TMPL_VAR NAME="LoginBranchname" --></div>
<!-- TMPL_IF NAME="table_loop" -->
<form name="items" class="checkboxed">
<h2>Items in batch number <!-- TMPL_VAR NAME="batch_id" --></h2>
<table>
<!-- TMPL_LOOP NAME="table_loop" -->
<!-- TMPL_IF NAME="header_fields" -->
<tr>
<!-- TMPL_LOOP NAME="header_fields" -->
<th><!-- TMPL_VAR NAME="field_label" --></th>
<!-- /TMPL_LOOP -->
</tr>
<!-- TMPL_ELSE -->
<tr>
<!-- TMPL_LOOP NAME="text_fields" -->
<!-- TMPL_IF NAME="select_field" -->
<td align="center"><input type="checkbox" name="action" value="<!-- TMPL_VAR NAME="field_value" -->"></td>
<!-- TMPL_ELSE -->
<td><!-- TMPL_VAR NAME="field_value" --></td>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</tr>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</table>
</form>
<!-- TMPL_ELSE -->
<div class="dialog message"><h4>There are no items in Batch <!-- TMPL_VAR NAME="batch_id" --> yet</h4>
<p>Use the toolbar above to add items.</p></div>
<!-- /TMPL_IF -->
</div>
<!-- TMPL_IF NAME="duplicate_message" -->
<div class="yui-u">
<div class="dialog message">
<strong><!-- TMPL_VAR NAME="duplicate_count" --> duplicate item(s) found</strong> and removed from batch <!-- TMPL_VAR NAME="batch_id" -->.
</div>
</div>
<!-- /TMPL_IF -->
</div>
<fieldset class="action">
<span id="cancel"><a class="cancel" href="/cgi-bin/koha/patroncards/manage.pl?card_element=batch">Cancel</a></span>
</fieldset>
</div>
</div>
<div class="yui-b">
<!-- TMPL_INCLUDE NAME="patroncards-menu.inc" -->
</div>
</div>
</div>
<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
136 changes: 136 additions & 0 deletions patroncards/edit-batch.pl
@@ -0,0 +1,136 @@
#!/usr/bin/perl
#
# Copyright 2006 Katipo Communications.
# Parts Copyright 2009 Foundations Bible College.
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA

use strict;
use warnings;
use vars qw($debug);

use CGI;
use autouse 'Data::Dumper' => qw(Dumper);

use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);
use C4::Branch qw(get_branch_code_from_name);
use C4::Creators::Lib 1.000000 qw(get_card_summary html_table);
use C4::Patroncards::Batch 1.000000;

my $cgi = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "patroncards/edit-batch.tmpl",
query => $cgi,
type => "intranet",
authnotrequired => 0,
flagsrequired => { catalogue => 1 },
debug => 1,
}
);

my $err = 0;
my $duplicate_count = undef;
my $duplicate_message = undef;
my $db_rows = {};
my $batch = undef;
my $display_columns = [ {_card_number => {label => 'Card Number', link_field => 0}},
{_summary => {label => 'Summary', link_field => 0}},
{borrowernumber => {label => 'Borrower Number', link_field => 0}},
{select => {label => 'Select', value => '_label_id'}},
];
my $op = $cgi->param('op') || 'new';
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || undef;
my @label_ids = $cgi->param('label_id') if $cgi->param('label_id');
my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
my @borrower_numbers = $cgi->param('borrower_number') if $cgi->param('borrower_number');
my $errstr = $cgi->param('error') || '';

my $branch_code = get_branch_code_from_name($template->param('LoginBranchname'));

if ($op eq 'remove') {
$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
foreach my $label_id (@label_ids) {
$err = $batch->remove_item($label_id);
}
if ($err) {
print $cgi->redirect("edit-batch.pl?op=edit&batch_id=$batch_id&error=403"); # this allows us to avoid problems with the user hitting their refresh button
exit;
}
}
elsif ($op eq 'delete') {
$err = C4::Creators::Batch::delete(batch_id => $batch_id, branch_code => $branch_code);
if ($err) {
print $cgi->redirect("edit-batch.pl?op=edit&batch_id=$batch_id&error=404");
exit;
}
}
elsif ($op eq 'add') {
$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
$batch = C4::Patroncards::Batch->new(branch_code => $branch_code) if $batch == -2;
if ($branch_code){
foreach my $borrower_number (@borrower_numbers) {
$err = $batch->add_item($borrower_number);
}
if ($err) {
print $cgi->redirect("edit-batch.pl?op=edit&batch_id=$batch_id&error=401");
exit;
}
}
else {
print $cgi->redirect("edit-batch.pl?op=edit&batch_id=$batch_id&error=402");
exit;
}
}
elsif ($op eq 'de_duplicate') {
$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
$duplicate_count = $batch->remove_duplicates();
$duplicate_message = 1 if $duplicate_count != -1;
if ($duplicate_count == -1) {
print $cgi->redirect("edit-batch.pl?op=edit&batch_id=$batch_id&error=405");
exit;
}
}
elsif ($op = 'edit') {
$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
}
elsif ($op eq 'new') {
$batch = C4::Patroncards::Batch->new(branch_code => $branch_code);
$batch_id = $batch->get_attr('batch_id');
}
else {
warn sprintf('Batch edit interface called an unsupported operation: %s',$op);
print $cgi->redirect("manage.pl?card_element=batch&error=202") if $err;
exit;
}

my $items = $batch->get_attr('items');
$db_rows = get_card_summary(items => $items, batch_id => $batch_id);

my $table = html_table($display_columns, $db_rows);

$template->param(
op => $op,
batch_id => $batch_id,
table_loop => $table,
duplicate_message => $duplicate_message,
duplicate_count => $duplicate_count,
error => ($errstr ? 1 : 0),
$errstr => 1,
);

output_html_with_http_headers $cgi, $cookie, $template->output;

0 comments on commit 666c70d

Please sign in to comment.