--- .../prog/en/modules/tools/batchMod.tmpl | 151 ++++++++++++++++ .../prog/en/modules/tools/tools-home.tmpl | 10 + tools/batchMod.pl | 181 ++++++++++++++++++++ 3 files changed, 342 insertions(+), 0 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod.tmpl create mode 100755 tools/batchMod.pl
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod.tmpl new file mode 100644 index 0000000..138b81e --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod.tmpl @@ -0,0 +1,151 @@ +<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --> +<title>Koha › Tools › Inventory</title> +<!-- TMPL_INCLUDE NAME="doc-head-close.inc" --> +<!-- TMPL_INCLUDE NAME="calendar.inc" --> +</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> › + <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › + <!-- TMPL_IF name="del" --> + <a href="/cgi-bin/koha/tools/batchMod.pl?del=1">Delete batches of notices</a> + <!-- TMPL_ELSE --> + <a href="/cgi-bin/koha/tools/batchMod.pl">Modify batches of notices</a> + <!-- /TMPL_IF --> +</div> + +<div id="doc3" class="yui-t2"> + <div id="bd"> + <div id="yui-main"> + <div class="yui-b"> + <h1>Batch <!-- TMPL_IF name="del" -->deletion<!-- TMPL_ELSE -->modification<!-- /TMPL_IF --></h1> + <!-- TMPL_UNLESS name="op" --> + <div class="yui-g"> + <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/batchMod.pl"> + <fieldset class="rows"> + <legend>Use a barcode file</legend> + <ol> + <li><label for="uploadbarcodes">Barcode file: </label> <input type="file" id="uploadbarcodes" name="uploadbarcodes"></input></li> + </ol> + </fieldset> + <fieldset class="rows"> + <legend>Or scan items one-by-one</legend> + <ol> + <li> + <label for="barcodelist">Barcodes list (one barcode per line): </label> + <textarea rows="10" cols="30" name="barcodelist"></textarea> + </li> + </ol> + </fieldset> + <input type="hidden" name="op" value="barcodes" /> + <!-- TMPL_IF name="del" --><input type="hidden" name="del" value="1" /><!-- /TMPL_IF --> + <fieldset class="action"> + <input type="submit" value="Continue" class="button" /> + </fieldset> + </form> + </div> + <!-- /TMPL_UNLESS --> + <!-- TMPL_IF name="actions" --> + <!-- TMPL_IF name="itemsloop" --> + <table> + <tr> + <th>title</th> + <th>homebranch</th> + <th>holdingbranch</th> + <!-- TMPL_LOOP name="authloop" --> + <th><!-- TMPL_VAR name="description" --></th> + <!-- /TMPL_LOOP --> + <!-- TMPL_IF name="itemtypes" --> + <th>item type</th> + <!-- /TMPL_UNLESS --> + </tr> + <!-- TMPL_LOOP name="itemsloop" --> + <tr> + <td><!-- TMPL_VAR name="title" --></td> + <td><!-- TMPL_VAR name="homebranch" --></td> + <td><!-- TMPL_VAR name="holdingbranch" --></td> + <!-- TMPL_LOOP name="authloop" --> + <td><!-- TMPL_VAR name="authvalue" --></td> + <!-- /TMPL_LOOP --> + <!-- TMPL_IF name="itemtypes" --> + <td><!-- TMPL_VAR name="itemtypedesc" --></td> + <!-- /TMPL_UNLESS --> + </tr> + <!-- /TMPL_LOOP --> + </table> + <form method="post" action="/cgi-bin/koha/tools/batchMod.pl"> + <!-- TMPL_IF name="del" --> + <p>This will delete the selected items.</p> + <input type="hidden" name="del" value="1" /> + <!-- TMPL_ELSE --> + <fieldset class="rows"> + <legend>Change items' properties</legend> + <ol> + <!-- TMPL_LOOP name="authloop" --> + <li> + <label for="<!-- TMPL_VAR name="authcode" -->">Change <!-- TMPL_VAR name="description" --></label> + <select name="<!-- TMPL_VAR name="authcode" -->" id="<!-- TMPL_VAR name="authcode" -->"> + <option selected="selected" value="0">No change</option> + <!-- TMPL_LOOP name="values" --> + <option value="<!-- TMPL_VAR name="id" -->"><!-- TMPL_VAR NAME="lib" --></option> + <!-- /TMPL_LOOP --> + </select> + </li> + <!-- /TMPL_LOOP --> + <li> + <label for="homebranch">Change the homebranch</label> + <select name="homebranch" id="homebranch"> + <option selected="selected" value="0">No change</option> + <!-- TMPL_LOOP name="branches" --> + <option value="<!-- TMPL_VAR name="code" -->"><!-- TMPL_VAR NAME="name" --></option> + <!-- /TMPL_LOOP --> + </select> + </li> + <li> + <label for="holdingbranch">Change the holdingbranch</label> + <select name="holdingbranch" id="holdingbranch"> + <option selected="selected" value="0">No change</option> + <!-- TMPL_LOOP name="branches" --> + <option value="<!-- TMPL_VAR name="code" -->"><!-- TMPL_VAR NAME="name" --></option> + <!-- /TMPL_LOOP --> + </select> + </li> + <!-- TMPL_IF name="itemtypes" --> + <li> + <label for="itemtypes">Change the itemtypes</label> + <select name="itemtypes" id="itemtypes"> + <option selected="selected" value="0">No change</option> + <!-- TMPL_LOOP name="itemtypes" --> + <option value="<!-- TMPL_VAR name="itemtype" -->"><!-- TMPL_VAR name="description" --></option> + <!-- /TMPL_LOOP --> + </li> + <!-- /TMPL_IF --> + <li> + <label for="itemnote">Change item note</label> + <textarea name="itemnote" id="itemnote" rows="10" cols="40" ></textarea> + </li> + </ol> + </fieldset> + <!-- /TMPL_IF --> + <input type="hidden" name="itemslst" value="<!-- TMPL_VAR name="itemslst" -->"/> + <fieldset class="action"> + <input type="submit" value="Go" class="button" /> + </fieldset> + </form> + <!-- TMPL_ELSE --> + <h3>No results!</h3> + <a href="javascript:window.history.back()">Go back</a> + <!-- /TMPL_IF --> + <!-- /TMPL_IF --> + </div> + </div> + <div class="yui-b"> + <!-- TMPL_INCLUDE NAME="tools-menu.inc" --> + </div> + </div> +</div> +</body> +</html> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl index be817d9..9d13073 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl @@ -67,6 +67,16 @@ <dd>Perform inventory (stocktaking) of your catalog</dd> <!-- /TMPL_IF --> + <!-- TMPL_IF NAME="CAN_user_tools_batchmod" --> + <dt><a href="/cgi-bin/koha/tools/batchMod.pl">Modify a queryset of items</a></dt> + <dd>Perform batch modification of items</dd> + <!-- /TMPL_IF --> + + <!-- TMPL_IF NAME="CAN_user_tools_batchdel" --> + <dt><a href="/cgi-bin/koha/tools/batchMod.pl?del=1">Delete a queryset of items</a></dt> + <dd>Perform batch deletion of items</dd> + <!-- /TMPL_IF --> + </dl> </div> <div class="yui-u"> diff --git a/tools/batchMod.pl b/tools/batchMod.pl new file mode 100755 index 0000000..dd3c6af --- /dev/null +++ b/tools/batchMod.pl @@ -0,0 +1,181 @@ +#!/usr/bin/perl + +# Copyright 2000-2009 Biblibre S.A +# John Soros <john.so...@biblibre.com> +# +# 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; + +#need to open cgi and get the fh before anything else opens a new cgi context (see C4::Auth) +use CGI; +my $input = new CGI; +my $barcodefh = $input->upload('uploadbarcodes'); + +use C4::Auth; +use C4::Context; +use C4::Output; +use C4::Branch qw(GetBranches); +use C4::Koha qw(GetAuthorisedValues GetAuthValCode); +use C4::Items qw(GetItemnumberFromBarcode GetItem ModItem DelItemCheck); +use C4::Biblio qw(GetBiblioData); +use C4::Koha qw(GetItemTypes); + + +my ($template, $borrowernumber, $cookie) + = get_template_and_user({template_name => "tools/batchMod.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {tools => 'batchmod'}, + debug => 1, + }); + +#get all input vars and put it in a hash +my $invars = $input->Vars; + +# Global item status lists (this has proven to be very handy :) +my $authloop = []; +my $authvals = [['items.notforloan', 'Item not for loan', 'notforloan'], + ['items.itemlost', 'Item lost', 'itemlost'], + ['items.wthdrawn', 'item withdrawn', 'sele'], + ['items.damaged', 'item damaged', 'damaged'], + ['items.location', 'item location', 'location'], + ['items.ccode', 'items.ccode FIXME???', 'ccode'], + ]; + +my $itemlevelpref = C4::Context->preference('item-level_itypes'); +#we use item -level itemtypes +if ( $itemlevelpref ){ + push(@$authvals, ['items.itype', 'itemtype', 'itype']); +} +if ( $invars->{op} && $invars->{op} eq 'barcodes'){ + #Parse barcodes list + my @barcodelist; + if ( $invars->{'uploadbarcodes'} && length($invars->{'uploadbarcodes'})>0){ + while (my $barcode=<$barcodefh>){ + chomp $barcode; + push @barcodelist, $barcode; + } + } + if ( $invars->{barcodelist} && length($invars->{barcodelist}) > 0){ + @barcodelist = split(/\s\n/, $invars->{barcodelist}); + } + #get all branches + my $brancheshash = GetBranches(); + my $branches = []; + for my $branchcode (keys %$brancheshash){ + my $branch; + $branch->{'name'} = $brancheshash->{$branchcode}->{'branchname'}; + $branch->{'code'} = $branchcode; + push @$branches, $branch; + } + + #get all item statuses + for my $field (@$authvals){ + my $fieldstatusauth = {}; + my ($fieldname, $fielddesc, $hashfdname) = @$field; + $fieldstatusauth->{authcode} = GetAuthValCode($fieldname); + if ($fieldstatusauth->{authcode} && length($fieldstatusauth->{authcode}) > 0){ + $fieldstatusauth->{values} = GetAuthorisedValues($fieldstatusauth->{authcode}); + $fieldstatusauth->{fieldname} = $fieldname; + $fieldstatusauth->{description} = $fielddesc; + $fieldstatusauth->{itemfieldname} = $hashfdname; + push @$authloop, $fieldstatusauth; + } + } + my $itemtypes = []; + #we use biblio level itype + if ( ! $itemlevelpref){ + my $itypes = GetItemTypes(); + for my $key (keys %$itypes){ + push(@$itemtypes, $itypes->{$key}); + } + } + #build items list + my @items; + my $itemslst = ''; + if (scalar @barcodelist > 0){ + for my $barcode (@barcodelist){ + my $itemno = GetItemnumberFromBarcode($barcode); + my $item = GetItem($itemno, $barcode); + my $iteminfo = GetBiblioData($item->{biblionumber}); + for my $field (qw(title isbn itemtype)){ + $item->{$field} = $iteminfo->{$field}; + } +#kind of flakey, though we can be pretty sure the values will be in the same order as in the authloop +#have to use this since in html::template::pro i can't access one loop from inside an other, +#and variable substitution doesn't work (<!-- TMPL_VAR name="<!-- TMPL_VAR name="foo" -->" -->) +#this pushes a list of authorized valuse into each item's hash + my $itemauthloop = []; + for my $authfield (@$authloop){ + my $authvaluename; +#looking for the authvalues human-readable form + for my $val (@{$authfield->{values}}){ + if( $item->{$authfield->{itemfieldname}} eq $val->{lib} || $item->{$authfield->{itemfieldname}} eq $val->{authorised_value}){ + $authvaluename = $val->{lib}; + } + } + if ( ! $authvaluename){ + $authvaluename = "Not found or invalid"; + } + push(@$itemauthloop, { 'authvalue' => $authvaluename} ); + } + for my $type (@$itemtypes){ + if ( $item->{itemtype} eq $type->{itemtype} ) { + $item->{itemtypedesc} = $type->{description}; + } + } + $item->{authloop} = $itemauthloop; + push @items, $item; + $itemslst .= $item->{'itemnumber'} . ','; + } + } + + $template->param( 'itemsloop' => \...@items, + 'authloop' => $authloop, + 'branches' => $branches, + 'actions' => 1, + 'op' => '1', + 'itemslst' => $itemslst, + 'itemtypes' => $itemtypes, + ); +} elsif ( $invars->{'itemslst'} ) { + for my $itemno ( split(',', $invars->{itemslst}) ) { + my $item = GetItem($itemno); + if ( $invars->{'del'} ) { + DelItemCheck(C4::Context->dbh, $item->{'biblionumber'}, $item->{'itemnumber'}) + } else { + for my $auth (@$authvals){ + my ($authfieldname, $description, $hashfdname) = @$auth; + my $authcode = GetAuthValCode($authfieldname); + if ($invars->{$authcode} && $invars->{$authcode} ne '0'){ + $item->{$hashfdname}=$invars->{$authcode}; + } + } + if ($invars->{holdingbranch} && $invars->{holdingbranch} ne '0'){ + $item->{holdingbranch} = $invars->{holdingbranch}; + } + if ($invars->{homebranch} && $invars->{homebranch} ne '0'){ + $item->{homebranch} = $invars->{homebranch}; + } + ModItem($item, $item->{biblionumber}, $item->{itemnumber}); + } + } +} +$template->param('del' => $input->param('del')); +output_html_with_http_headers $input, $cookie, $template->output; -- 1.6.0.4 _______________________________________________ Koha-patches mailing list Koha-patches@lists.koha.org http://lists.koha.org/mailman/listinfo/koha-patches