[Koha-patches] [PATCH] New Tool: Set Item Type on Copies based on Call Number
Michael Hafen
mdhafen at tech.washk12.org
Thu Nov 6 23:44:43 CET 2008
This tool checkes all items at a branch with no itype set, and sets it
if the itemcallnumber starts with what the user entered. Also sets the
biblio level itemtype if it isn't set.
---
.../intranet-tmpl/prog/en/includes/tools-menu.inc | 3 +
.../prog/en/modules/tools/set-itype.tmpl | 78 +++++++++++
.../prog/en/modules/tools/tools-home.tmpl | 5 +
tools/set-itype.pl | 139 ++++++++++++++++++++
4 files changed, 225 insertions(+), 0 deletions(-)
create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/set-itype.tmpl
create mode 100755 tools/set-itype.pl
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc
index 2c94cb3..8d7d382 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc
@@ -42,6 +42,9 @@
<!-- TMPL_IF NAME="CAN_user_tools_export_catalog" -->
<li><a href="/cgi-bin/koha/tools/export.pl">Export bibs/holdings</a></li>
<!-- /TMPL_IF -->
+ <!-- TMPL_IF NAME="CAN_user_tools" -->
+ <li><a href="/cgi-bin/koha/tools/set-itype.pl">Set Item Type on copies</a></li>
+ <!-- /TMPL_IF -->
<!-- TMPL_IF NAME="CAN_user_tools_import_patrons" -->
<li><a href="/cgi-bin/koha/tools/import_borrowers.pl">Import patrons</a></li>
<!-- /TMPL_IF -->
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/set-itype.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/set-itype.tmpl
new file mode 100644
index 0000000..7846016
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/set-itype.tmpl
@@ -0,0 +1,78 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<title>Koha › Tools › Set Item Type</title>
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+</head>
+<body>
+
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+<!-- TMPL_INCLUDE NAME="patron-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="OP" --><a href="/cgi-bin/koha/tools/set-itype.pl"><!-- /TMPL_IF -->Set Item Type<!-- TMPL_IF NAME="OP" --></a><!-- /TMPL_IF --></div>
+
+<div id="doc3" class="yui-t2">
+ <div id="bd">
+ <div id="yui-main">
+ <div class="yui-b">
+ <div class="yui-g">
+ <div class="yui-u first">
+<!-- TMPL_IF name="warnings" -->
+ <div class="error">
+ <ul>
+ <!-- TMPL_IF NAME="NO_BRANCH" --><li>Don't know where you are, can't continue</li><!-- /TMPL_IF -->
+ <!-- TMPL_IF NAME="NO_ITYPE" --><li>No Item Type Set</li><!-- /TMPL_IF -->
+ </ul>
+ </div>
+<!-- /TMPL_IF -->
+<!-- TMPL_IF name="OP" -->
+ <div class="dialog message">
+ <h1>Results of Setting Item Type</h1>
+ <ul class="data">
+ <li><!-- TMPL_VAR NAME="ITEMS_SET" --> copies set.</li>
+ <li><!-- TMPL_VAR NAME="BIBS_SET" --> biblios set.</li>
+ </ul>
+ </div>
+ <a href="/cgi-bin/koha/tools/set-itype.pl">Back</a>
+<!-- TMPL_ELSE -->
+ <h1>Set Item Type On Copies</h1>
+ <form method="post" action="/cgi-bin/koha/tools/set-itype.pl">
+ <fieldset class="rows">
+ <ol>
+ <li>
+ <label for="search">Call Number Starts With: </label>
+ <input name="search"/>
+ </li>
+
+ <!-- TMPL_IF NAME="ITEM_ITEMTYPES" --><li>
+ <label for="itype">Item Type: </label>
+ <select id="itype" name="itype">
+ <!-- TMPL_LOOP NAME="itemtypeloop" -->
+ <option value="<!-- TMPL_VAR name="value" -->"><!-- TMPL_VAR name="description" --></option>
+ <!-- /TMPL_LOOP -->
+ </select>
+ </li><!-- /TMPL_IF -->
+
+ <!-- TMPL_IF NAME="branchloop" -->
+ <label for="branch">Branch: </label>
+ <select id="branch" name="branch">
+ <!-- TMPL_LOOP NAME="branchloop" -->
+ <option value="<!-- TMPL_VAR NAME="value" -->"<!-- TMPL_IF NAME="selected" --> selected="selected"<!-- /TMPL_IF -->><!-- TMPL_VAR NAME="label" --></option>
+ <!-- /TMPL_LOOP -->
+ </select>
+ <!-- /TMPL_IF -->
+ </ol>
+ </fieldset>
+ <fieldset class="action">
+ <input type="hidden" name="op" value="Set" />
+ <input type="submit" name="button" value="Set" class="submit" /> <a href="/cgi-bin/koha/tools/tools-home.pl" class="cancel">Cancel</a>
+ </fieldset>
+ </form>
+<!-- /TMPL_IF -->
+ </div>
+ </div>
+ </div>
+ </div>
+<div class="yui-b noprint">
+ <!-- TMPL_INCLUDE NAME="tools-menu.inc" -->
+</div>
+</div>
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
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 75d8104..3c6f101 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
@@ -81,6 +81,11 @@
<dd>Export bibliographic and holdings data</dd>
<!-- /TMPL_IF -->
+ <!-- TMPL_IF NAME="CAN_user_tools" -->
+ <dt><a href="/cgi-bin/koha/tools/set-itype.pl">Set Item Type on copies</a></dt>
+ <dd>Set the item type on copies where it isn't set. Also set the item type on biblio records of those copies if it isn't set there.</dd>
+ <!-- /TMPL_IF -->
+
<!-- TMPL_IF NAME="CAN_user_tools_import_patrons" -->
<dt><a href="/cgi-bin/koha/tools/import_borrowers.pl">Import patrons</a></dt>
<dd>Import patron data</dd>
diff --git a/tools/set-itype.pl b/tools/set-itype.pl
new file mode 100755
index 0000000..f41d30f
--- /dev/null
+++ b/tools/set-itype.pl
@@ -0,0 +1,139 @@
+#!/usr/bin/perl
+
+# 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
+#
+# Written by Michael Hafen mdhafen at tech.washk12.org on Nov. 2008
+
+
+=head1 set-itype.pl
+
+This script sets the item level itype where it isn't set by examining the call number
+
+=cut
+
+use strict;
+use CGI;
+use C4::Auth;
+use C4::Output;
+use C4::Biblio; # GetBiblio
+use C4::Items; # AddItem GetItemnumberFromBarcode
+use C4::Koha; # getitemtypeinfo GetItemTypes
+
+my $cgi = new CGI;
+
+# getting the template
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+ {
+ template_name => "tools/set-itype.tmpl",
+ query => $cgi,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => { management => 1, tools => 1 },
+ }
+);
+
+my $dbh = C4::Context->dbh;
+my $op = $cgi->param( 'op' );
+my $branch = $cgi->param( 'branch' ) || C4::Context->userenv->{'branch'};
+my $search = $cgi->param( 'search' );
+my $itype = $cgi->param( 'itype' );
+
+my $itemtypes = GetItemTypes;
+my ( $items_set, $bibs_set ) = ( 0, 0 );
+
+$itype = '' unless ( $itemtypes->{$itype}{itemtype} );
+
+$template->param( NO_BRANCH => 1 ) unless ( $branch );
+$template->param( NO_ITYPE => 1 ) unless ( $itype );
+
+if ( $op eq 'Set' && $search && $itype ) {
+ my $query = "
+SELECT i.itemnumber, i.biblioitemnumber, i.biblionumber, i.itemcallnumber,
+ bi.itemtype
+FROM items AS i
+CROSS JOIN biblioitems AS bi USING ( biblioitemnumber )
+WHERE ( itype = '' OR itype IS NULL )
+ AND homebranch = ". $dbh->quote( $branch );
+ my $sth = $dbh->prepare( $query );
+ $sth->execute;
+
+ while ( my @row = $sth->fetchrow_array ) {
+ my ( $itemnumber, $biblioitem, $biblio, $callnum, $itemtype ) = @row;
+
+ next unless ( $callnum =~ /^$search/i );
+
+ my $item = { 'itype' => $itype };
+ ModItem( $item, $biblio, $itemnumber );
+ $items_set++;
+
+ unless ( $itemtype ) {
+ my $framework = GetFrameworkCode( $biblio );
+ $framework = '' unless ( $framework );
+ my ( $itypetag, $itypefield ) = GetMarcFromKohaField( "biblioitems.itemtype", $framework );
+ my $record = GetMarcBiblio( $biblio );
+
+ if ( my $koha_field = $record->field( $itypetag ) ) {
+ $koha_field->update( $itypefield => $itype );
+ } else {
+ my $new_field = new MARC::Field( $itypetag, '0', '0',
+ $itypefield => $itype );
+ $record->add_fields( $new_field );
+ }
+
+ &ModBiblio( $record, $biblio, $framework );
+ $bibs_set++;
+ }
+ }
+
+ $template->param(
+ OP => $op,
+ ITEMS_SET => $items_set,
+ BIBS_SET => $bibs_set,
+ );
+}
+
+my @itemtypesloop;
+foreach my $thisitemtype (sort keys %$itemtypes) {
+ my %row =(value => $thisitemtype,
+ description => $itemtypes->{$thisitemtype}->{'description'},
+ );
+ push @itemtypesloop, \%row;
+}
+
+unless ( C4::Context->preference('IndependantBranches') ) {
+ my $branches = GetBranches();
+ my @branchloop;
+
+ foreach my $thisbranch ( sort keys %$branches ) {
+ my %row = (
+ value => $thisbranch,
+ label => $branches->{$thisbranch}->{'branchname'},
+ selected => ( $branches->{$thisbranch}->{'branchcode'} eq $branch ),
+ );
+ push @branchloop, \%row;
+ }
+ $template->param(
+ branchloop => \@branchloop,
+ );
+}
+
+$template->param(
+ itemtypeloop => \@itemtypesloop,
+ ITEM_ITEMTYPES => C4::Context->preference('item-level_itypes'),
+ );
+
+#writing the template
+output_html_with_http_headers $cgi, $cookie, $template->output;
--
1.5.6.3
More information about the Koha-patches
mailing list