[Koha-patches] [PATCH] Rotating Collections
Kyle M Hall
kyle.m.hall at gmail.com
Tue Jan 19 14:10:51 CET 2010
Patch submitted by request from Frédéric Demians
---
C4/RotatingCollections.pm | 479 ++++++++++++++++++++
circ/returns.pl | 1 +
installer/data/mysql/updatedatabase.pl | 7 +
.../en/modules/rotating_collections/addItems.tmpl | 78 ++++
.../rotating_collections/editCollections.tmpl | 112 +++++
.../rotating_collections/rotatingCollections.tmpl | 38 ++
.../rotating_collections/transferCollection.tmpl | 38 ++
rotating_collections/addItems.pl | 82 ++++
rotating_collections/editCollections.pl | 103 +++++
rotating_collections/rotatingCollections.pl | 34 ++
rotating_collections/transferCollection.pl | 66 +++
11 files changed, 1038 insertions(+), 0 deletions(-)
create mode 100644 C4/RotatingCollections.pm
create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tmpl
create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tmpl
create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/rotatingCollections.tmpl
create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/transferCollection.tmpl
create mode 100755 rotating_collections/addItems.pl
create mode 100755 rotating_collections/editCollections.pl
create mode 100755 rotating_collections/rotatingCollections.pl
create mode 100755 rotating_collections/transferCollection.pl
diff --git a/C4/RotatingCollections.pm b/C4/RotatingCollections.pm
new file mode 100644
index 0000000..82a4d5e
--- /dev/null
+++ b/C4/RotatingCollections.pm
@@ -0,0 +1,479 @@
+package C4::RotatingCollections;
+
+# $Id: RotatingCollections.pm,v 0.1 2007/04/20 kylemhall
+
+# This package is inteded to keep track of what library
+# Items of a certain collection should be at.
+
+# Copyright 2007 Kyle Hall
+#
+# 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;
+
+require Exporter;
+
+use C4::Context;
+use C4::Circulation;
+
+use DBI;
+
+use Data::Dumper;
+
+use vars qw($VERSION @ISA @EXPORT);
+
+# set the version for version checking
+$VERSION = 0.01;
+
+=head1 NAME
+
+C4::RotatingCollections - Functions for managing rotating collections
+
+=head1 FUNCTIONS
+
+=over 2
+
+=cut
+
+ at ISA = qw( Exporter );
+ at EXPORT = qw(
+ CreateCollection
+ UpdateCollection
+ DeleteCollection
+
+ GetItemsInCollection
+
+ GetCollection
+ GetCollections
+
+ AddItemToCollection
+ RemoveItemFromCollection
+ TransferCollection
+
+ GetCollectionItemBranches
+
+ getItemnumberByBarcode
+);
+
+=item CreateCollection
+ ( $success, $errorcode, $errormessage ) = CreateCollection( $title, $description );
+ Creates a new collection
+
+ Input:
+ $title: short description of the club or service
+ $description: long description of the club or service
+
+ Output:
+ $success: 1 if all database operations were successful, 0 otherwise
+ $errorCode: Code for reason of failure, good for translating errors in templates
+ $errorMessage: English description of error
+=cut
+sub CreateCollection {
+ my ( $title, $description ) = @_;
+
+ ## Check for all neccessary parameters
+ if ( ! $title ) {
+ return ( 0, 1, "No Title Given" );
+ }
+ if ( ! $description ) {
+ return ( 0, 2, "No Description Given" );
+ }
+
+ my $success = 1;
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth;
+ $sth = $dbh->prepare("INSERT INTO collections ( colId, colTitle, colDesc )
+ VALUES ( NULL, ?, ? )");
+ $sth->execute( $title, $description ) or return ( 0, 3, $sth->errstr() );
+ $sth->finish;
+
+ return 1;
+
+}
+
+=item UpdateCollection
+ ( $success, $errorcode, $errormessage ) = UpdateCollection( $colId, $title, $description );
+ Updates a collection
+
+ Input:
+ $colId: id of the collection to be updated
+ $title: short description of the club or service
+ $description: long description of the club or service
+
+ Output:
+ $success: 1 if all database operations were successful, 0 otherwise
+ $errorCode: Code for reason of failure, good for translating errors in templates
+ $errorMessage: English description of error
+=cut
+sub UpdateCollection {
+ my ( $colId, $title, $description ) = @_;
+
+ ## Check for all neccessary parameters
+ if ( ! $colId ) {
+ return ( 0, 1, "No Id Given" );
+ }
+ if ( ! $title ) {
+ return ( 0, 2, "No Title Given" );
+ }
+ if ( ! $description ) {
+ return ( 0, 3, "No Description Given" );
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth;
+ $sth = $dbh->prepare("UPDATE collections
+ SET
+ colTitle = ?, colDesc = ?
+ WHERE colId = ?");
+ $sth->execute( $title, $description, $colId ) or return ( 0, 4, $sth->errstr() );
+ $sth->finish;
+
+ return 1;
+
+}
+
+=item DeleteCollection
+ ( $success, $errorcode, $errormessage ) = DeleteCollection( $colId );
+ Deletes a collection of the given id
+
+ Input:
+ $colId : id of the Archtype to be deleted
+
+ Output:
+ $success: 1 if all database operations were successful, 0 otherwise
+ $errorCode: Code for reason of failure, good for translating errors in templates
+ $errorMessage: English description of error
+=cut
+sub DeleteCollection {
+ my ( $colId ) = @_;
+
+ ## Paramter check
+ if ( ! $colId ) {
+ return ( 0, 1, "No Collection Id Given" );;
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth;
+
+ $sth = $dbh->prepare("DELETE FROM collections WHERE colId = ?");
+ $sth->execute( $colId ) or return ( 0, 4, $sth->errstr() );
+ $sth->finish;
+
+ return 1;
+}
+
+=item GetCollections
+ $collections = GetCollections();
+ Returns data about all collections
+
+ Output:
+ On Success:
+ $results: Reference to an array of associated arrays
+ On Failure:
+ $errorCode: Code for reason of failure, good for translating errors in templates
+ $errorMessage: English description of error
+=cut
+sub GetCollections {
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth = $dbh->prepare("SELECT * FROM collections");
+ $sth->execute() or return ( 1, $sth->errstr() );
+
+ my @results;
+ while ( my $row = $sth->fetchrow_hashref ) {
+ push( @results , $row );
+ }
+
+ $sth->finish;
+
+ return \@results;
+}
+
+=item GetItemsInCollection
+ ( $results, $success, $errorcode, $errormessage ) = GetItemsInCollection( $colId );
+ Returns information about the items in the given collection
+
+ Input:
+ $colId: The id of the collection
+
+ Output:
+ $results: Reference to an array of associated arrays
+ $success: 1 if all database operations were successful, 0 otherwise
+ $errorCode: Code for reason of failure, good for translating errors in templates
+ $errorMessage: English description of error
+=cut
+sub GetItemsInCollection {
+ my ( $colId ) = @_;
+
+ ## Paramter check
+ if ( ! $colId ) {
+ return ( 0, 0, 1, "No Collection Id Given" );;
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth = $dbh->prepare("SELECT
+ biblio.title,
+ items.itemcallnumber,
+ items.barcode
+ FROM collections, collections_tracking, items, biblio
+ WHERE collections.colId = collections_tracking.colId
+ AND collections_tracking.itemnumber = items.itemnumber
+ AND items.biblionumber = biblio.biblionumber
+ AND collections.colId = ? ORDER BY biblio.title");
+ $sth->execute( $colId ) or return ( 0, 0, 2, $sth->errstr() );
+
+ my @results;
+ while ( my $row = $sth->fetchrow_hashref ) {
+ push( @results , $row );
+ }
+
+ $sth->finish;
+
+ return \@results;
+}
+
+=item GetCollection
+ ( $colId, $colTitle, $colDesc, $colBranchcode ) = GetCollection( $colId );
+ Returns information about a collection
+
+ Input:
+ $colId: Id of the collection
+ Output:
+ $colId, $colTitle, $colDesc, $colBranchcode
+=cut
+sub GetCollection {
+ my ( $colId ) = @_;
+
+ my $dbh = C4::Context->dbh;
+
+ my ( $sth, @results );
+ $sth = $dbh->prepare("SELECT * FROM collections WHERE colId = ?");
+ $sth->execute( $colId ) or return 0;
+
+ my $row = $sth->fetchrow_hashref;
+
+ $sth->finish;
+
+ return (
+ $$row{'colId'},
+ $$row{'colTitle'},
+ $$row{'colDesc'},
+ $$row{'colBranchcode'}
+ );
+
+}
+
+=item AddItemToCollection
+ ( $success, $errorcode, $errormessage ) = AddItemToCollection( $colId, $itemnumber );
+ Adds an item to a rotating collection.
+
+ Input:
+ $colId: Collection to add the item to.
+ $itemnumber: Item to be added to the collection
+ Output:
+ $success: 1 if all database operations were successful, 0 otherwise
+ $errorCode: Code for reason of failure, good for translating errors in templates
+ $errorMessage: English description of error
+=cut
+sub AddItemToCollection {
+ my ( $colId, $itemnumber ) = @_;
+
+ ## Check for all neccessary parameters
+ if ( ! $colId ) {
+ return ( 0, 1, "No Collection Given" );
+ }
+ if ( ! $itemnumber ) {
+ return ( 0, 2, "No Itemnumber Given" );
+ }
+
+ if ( isItemInThisCollection( $itemnumber, $colId ) ) {
+ return ( 0, 2, "Item is already in the collection!" );
+ } elsif ( isItemInAnyCollection( $itemnumber ) ) {
+ return ( 0, 3, "Item is already in a different collection!" );
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth;
+ $sth = $dbh->prepare("INSERT INTO collections_tracking ( ctId, colId, itemnumber )
+ VALUES ( NULL, ?, ? )");
+ $sth->execute( $colId, $itemnumber ) or return ( 0, 3, $sth->errstr() );
+ $sth->finish;
+
+ return 1;
+
+}
+
+=item RemoveItemFromCollection
+ ( $success, $errorcode, $errormessage ) = RemoveItemFromCollection( $colId, $itemnumber );
+ Removes an item to a collection
+
+ Input:
+ $colId: Collection to add the item to.
+ $itemnumber: Item to be removed from collection
+
+ Output:
+ $success: 1 if all database operations were successful, 0 otherwise
+ $errorCode: Code for reason of failure, good for translating errors in templates
+ $errorMessage: English description of error
+=cut
+sub RemoveItemFromCollection {
+ my ( $colId, $itemnumber ) = @_;
+
+ ## Check for all neccessary parameters
+ if ( ! $itemnumber ) {
+ return ( 0, 2, "No Itemnumber Given" );
+ }
+
+ if ( ! isItemInThisCollection( $itemnumber, $colId ) ) {
+ return ( 0, 2, "Item is not in the collection!" );
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth;
+ $sth = $dbh->prepare("DELETE FROM collections_tracking
+ WHERE itemnumber = ?");
+ $sth->execute( $itemnumber ) or return ( 0, 3, $sth->errstr() );
+ $sth->finish;
+
+ return 1;
+}
+
+=item TransferCollection
+ ( $success, $errorcode, $errormessage ) = TransferCollection( $colId, $colBranchcode );
+ Transfers a collection to another branch
+
+ Input:
+ $colId: id of the collection to be updated
+ $colBranchcode: branch where collection is moving to
+
+ Output:
+ $success: 1 if all database operations were successful, 0 otherwise
+ $errorCode: Code for reason of failure, good for translating errors in templates
+ $errorMessage: English description of error
+=cut
+sub TransferCollection {
+ my ( $colId, $colBranchcode ) = @_;
+
+ ## Check for all neccessary parameters
+ if ( ! $colId ) {
+ return ( 0, 1, "No Id Given" );
+ }
+ if ( ! $colBranchcode ) {
+ return ( 0, 2, "No Branchcode Given" );
+ }
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth;
+ $sth = $dbh->prepare("UPDATE collections
+ SET
+ colBranchcode = ?
+ WHERE colId = ?");
+ $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() );
+ $sth->finish;
+
+ $sth = $dbh->prepare("SELECT barcode FROM items, collections_tracking
+ WHERE items.itemnumber = collections_tracking.itemnumber
+ AND collections_tracking.colId = ?");
+ $sth->execute( $colId ) or return ( 0, 4, $sth->errstr );
+ my @results;
+ while ( my $item = $sth->fetchrow_hashref ) {
+ my ( $dotransfer, $messages, $iteminformation ) = transferbook( $colBranchcode, $item->{'barcode'}, my $ignore_reserves = 1);
+ }
+
+
+
+ return 1;
+
+}
+
+=item getItemnumberByBarcode
+ $itemnumber = getItemnumberByBarcode( $barcode );
+=cut
+sub getItemnumberByBarcode {
+ my ( $barcode ) = @_;
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE barcode = ?");
+ $sth->execute( $barcode ) or return( 0 );
+
+ my $row = $sth->fetchrow_hashref;
+
+ my $itemnumber = $$row{'itemnumber'};
+ $sth->finish;
+
+ return( $itemnumber );
+}
+
+=item isItemInThisCollection
+$inCollection = isItemInThisCollection( $itemnumber, $colId );
+=cut
+sub isItemInThisCollection {
+ my ( $itemnumber, $colId ) = @_;
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth = $dbh->prepare("SELECT COUNT(*) as inCollection FROM collections_tracking WHERE itemnumber = ? AND colId = ?");
+ $sth->execute( $itemnumber, $colId ) or return( 0 );
+
+ my $row = $sth->fetchrow_hashref;
+
+ return $$row{'inCollection'};
+}
+
+=item isItemInAnyCollection
+$inCollection = isItemInAnyCollection( $itemnumber );
+=cut
+sub isItemInAnyCollection {
+ my ( $itemnumber ) = @_;
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth = $dbh->prepare("SELECT itemnumber FROM collections_tracking WHERE itemnumber = ?");
+ $sth->execute( $itemnumber ) or return( 0 );
+
+ my $row = $sth->fetchrow_hashref;
+
+ my $itemnumber = $$row{'itemnumber'};
+ $sth->finish;
+
+ if ( $itemnumber ) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+1;
+
+__END__
+
+=back
+
+=head1 AUTHOR
+
+Kyle Hall <kylemhall at gmail.com>
+
+=cut
diff --git a/circ/returns.pl b/circ/returns.pl
index 40eeed1..f4079ba 100755
--- a/circ/returns.pl
+++ b/circ/returns.pl
@@ -43,6 +43,7 @@ use C4::Items;
use C4::Members;
use C4::Branch; # GetBranches GetBranchName
use C4::Koha; # FIXME : is it still useful ?
+use C4::RotatingCollections;
my $query = new CGI;
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 4e1d1cf..915ada3 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -2269,6 +2269,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
SetVersion ($DBversion);
}
+$DBversion = "3.01.00.014";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'calcFineOnReturn', '0', '', 'Turns on the feature to calculate fines at the time of return and/or renewal as an alternative to the nightly cronjob fines system.', 'YesNo' )");
+ print "Upgrade to $DBversion done (add new syspref)\n";
+ SetVersion ($DBversion);
+}
+
$DBversion = "3.01.00.016";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('Babeltheque',0,'Turn ON Babeltheque content - See babeltheque.com to subscribe to this service','','YesNo')");
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tmpl
new file mode 100644
index 0000000..aa0f4d1
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tmpl
@@ -0,0 +1,78 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<title>Koha › Rotating Collections › Add Items
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+
+<div id="main">
+ <h1>Rotating Collections: Add/Remove Items</h1>
+
+ <div>
+ <br />
+ <!-- TMPL_IF NAME="previousActionAdd" -->
+ <!-- TMPL_IF NAME="addSuccess" -->
+ <div>Item with barcode '<!-- TMPL_VAR NAME="addedBarcode" -->' Added Succesfully!</div>
+ <!-- TMPL_ELSE -->
+ <div>Failed to add item with barcode '<!-- TMPL_VAR NAME="addedBarcode" -->'!</div>
+ <div>Reason: <strong><!-- TMPL_VAR NAME="failureMessage" --></strong></div>
+ <!-- /TMPL_IF -->
+ <!-- /TMPL_IF -->
+
+ <!-- TMPL_IF NAME="previousActionRemove" -->
+ <!-- TMPL_IF NAME="removeSuccess" -->
+ <div>Item with barcode '<!-- TMPL_VAR NAME="addedBarcode" -->' Removed Succesfully!</div>
+ <!-- TMPL_ELSE -->
+ <div>Failed to remove item with barcode '<!-- TMPL_VAR NAME="removedBarcode" -->'!</div>
+ <div>Reason: <strong><!-- TMPL_VAR NAME="failureMessage" --></strong></div>
+ <!-- /TMPL_IF -->
+ <!-- /TMPL_IF -->
+
+ <h3>Add Item to <i><!-- TMPL_VAR NAME="colTitle" --></i></h3>
+ </div>
+
+ <div>
+ <form action="addItems.pl" method="post">
+ <table>
+ <tr>
+ <td><label for="barcode">Barcode: </label></td>
+ <td><input type="text" id="barcode" name="barcode" /></td>
+ <td>
+ <input type="checkbox" name="removeItem" <!-- TMPL_IF NAME="removeChecked" -->checked<!-- /TMPL_IF--> >
+ <label for="removeItem">Remove Item from Collection</label>
+ </td>
+ </tr>
+
+ <input type="hidden" id="colId" name="colId" value="<!-- TMPL_VAR NAME="colId" -->" />
+ <input type="hidden" name="action" value="addItem" />
+ <tr><td><input type="submit" value="Submit" /></td></tr>
+ </table>
+ </form>
+ </div>
+
+ <br />
+ <div><a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating Collections Home</a></div>
+ <br />
+
+ <div>
+ <h2>Items In This Collection</h2>
+ <!-- TMPL_IF NAME="collectionItemsLoop" -->
+ <table>
+ <tr>
+ <th>Title</th>
+ <th>Callnumber</th>
+ <th>Barcode</th>
+ </tr>
+ <!-- TMPL_LOOP NAME="collectionItemsLoop" -->
+ <tr>
+ <td><!-- TMPL_VAR NAME="title" --></td>
+ <td><!-- TMPL_VAR NAME="itemcallnumber" --></td>
+ <td><!-- TMPL_VAR NAME="barcode" --></td>
+ </tr>
+ <!-- /TMPL_LOOP -->
+ </table>
+ <!-- TMPL_ELSE -->
+ There are no Items in this Collection.
+ <!-- /TMPL_IF -->
+ </div>
+
+</div>
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
\ No newline at end of file
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tmpl
new file mode 100644
index 0000000..784301c
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/editCollections.tmpl
@@ -0,0 +1,112 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<title>Koha › Rotating Collections › Edit Collectionss</title>
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+
+<div id="main">
+ <h1>Rotating Collections: Edit Collections</h1>
+
+ <!-- TMPL_IF NAME="previousActionCreate" -->
+ <!-- TMPL_IF NAME="createSuccess" -->
+ <div>Club Or Service '<!-- TMPL_VAR NAME="createdTitle" -->' Created Succesfully!</div>
+ <!-- TMPL_ELSE -->
+ <div>Collection '<!-- TMPL_VAR NAME="createdTitle" -->' Failed To Be Created!</div>
+ <div>Reason: <strong><!-- TMPL_VAR NAME="failureMessage" --></strong></div>
+ <!-- /TMPL_IF -->
+ <!-- /TMPL_IF -->
+
+ <!-- TMPL_IF NAME="previousActionDelete" -->
+ <!-- TMPL_IF NAME="DeleteSuccess" -->
+ <div>Collection Deleted Succesfully!</div>
+ <!-- TMPL_ELSE -->
+ <div>Collection Failed To Be Deleted!</div>
+ <!-- /TMPL_IF -->
+ <!-- /TMPL_IF -->
+
+ <!-- TMPL_IF NAME="previousActionUpdate" -->
+ <!-- TMPL_IF NAME="updateSuccess" -->
+ <div>Collection '<!-- TMPL_VAR NAME="updatedTitle" -->' Updated Succesfully!</div>
+ <!-- TMPL_ELSE -->
+ <div>Collection '<!-- TMPL_VAR NAME="updatedTitle" -->' Failed To Be Updated!</div>
+ <div>Reason: <strong><!-- TMPL_VAR NAME="failureMessage" --></strong></div>
+ <!-- /TMPL_IF -->
+ <!-- /TMPL_IF -->
+
+ <div>
+ <!-- TMPL_IF NAME="collectionsLoop" -->
+ <table>
+ <tr>
+ <th>Title</th>
+ <th>Description</th>
+ <th>Holding Library</th>
+ <td></td>
+ <td></td>
+ </tr>
+ <!-- TMPL_LOOP NAME="collectionsLoop" -->
+ <tr>
+ <td><!-- TMPL_VAR NAME="colTitle" --></td>
+ <td><!-- TMPL_VAR NAME="colDesc" --></td>
+ <td><!-- TMPL_VAR NAME="colBranchcode" --></td>
+ <td><a href="editCollections.pl?action=edit&colId=<!-- TMPL_VAR NAME="colId" -->">Edit</a></td>
+ <td><a href="editCollections.pl?action=delete&colId=<!-- TMPL_VAR NAME="colId" -->">Delete</a></td>
+ </tr>
+ <!-- /TMPL_LOOP -->
+ </table>
+ <!-- TMPL_ELSE -->
+ There are no Collections currently defined.
+ <!-- /TMPL_IF -->
+ </div>
+
+ <div>
+ <br />
+
+ <!-- TMPL_IF NAME="previousActionEdit" -->
+ <h1>Edit Collection</h1>
+ <!-- TMPL_ELSE -->
+ <h1>Create New Collection</h1>
+ <!-- /TMPL_IF -->
+
+ <form action="editCollections.pl" method="post">
+ <!-- TMPL_IF NAME="previousActionEdit" -->
+ <input type="hidden" name="action" value="update" />
+ <input type="hidden" name="colId" value="<!-- TMPL_VAR NAME="editColId" -->" />
+ <!-- TMPL_ELSE -->
+ <input type="hidden" name="action" value="create" />
+ <!-- /TMPL_IF -->
+
+ <table>
+ <tr>
+ <td>
+ <label for="title">Title: </label>
+ </td>
+ <td>
+ <input type="text" name="title" <!-- TMPL_IF NAME="editColTitle" --> value="<!-- TMPL_VAR NAME="editColTitle" -->" <!-- /TMPL_IF --> />
+ </td>
+ </tr>
+
+ <tr>
+ <td>
+ <label for="description">Description: </label>
+ </td>
+ <td>
+ <input type="text" size="50" name="description" <!-- TMPL_IF NAME="editColDescription" --> value="<!-- TMPL_VAR NAME="editColDescription" -->" <!-- /TMPL_IF --> />
+ </td>
+ </tr>
+
+ <tr>
+ <td colspan="2">
+ <!-- TMPL_IF NAME="previousActionEdit" -->
+ <input type="submit" value="Update" />
+ <!-- TMPL_ELSE -->
+ <input type="submit" value="Create" />
+ <!-- /TMPL_IF -->
+ </td>
+ </tr>
+ </table>
+ </form>
+ </div>
+
+ <br />
+ <div><a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating Collections Home</a></div>
+</div>
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
\ No newline at end of file
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/rotatingCollections.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/rotatingCollections.tmpl
new file mode 100644
index 0000000..5a46e13
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/rotatingCollections.tmpl
@@ -0,0 +1,38 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<title>Koha › Rotating Collections</title>
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+
+<div id="main">
+ <h1>Rotating Collections</h1>
+ <div>
+ <!-- TMPL_IF NAME="collectionsLoop" -->
+ <table>
+ <tr>
+ <th><strong>Title</strong></th>
+ <th>Description</strong></th>
+ <th>Current Location</th>
+ <th>Add Items</th>
+ <th>Transfer</th>
+ </tr>
+ <!-- TMPL_LOOP NAME="collectionsLoop" -->
+ <tr>
+ <td><!-- TMPL_VAR NAME="colTitle" --></td>
+ <td><!-- TMPL_VAR NAME="colDesc" --></td>
+ <td><!-- TMPL_VAR NAME="colBranchcode" --></td>
+ <td><a href="addItems.pl?colId=<!-- TMPL_VAR NAME="colId" -->">Edit Items</a></td>
+ <td><a href="transferCollection.pl?colId=<!-- TMPL_VAR NAME="colId" -->">Transfer</a></td>
+ </tr>
+ <!-- /TMPL_LOOP -->
+ </table>
+ <!-- TMPL_ELSE -->
+ There are no Collections currently defined.
+ <!-- /TMPL_IF -->
+ </div>
+
+ <div>
+ <div><a href="editCollections.pl">Create New Collection</a></div>
+ </div>
+
+</div>
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
\ No newline at end of file
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/transferCollection.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/transferCollection.tmpl
new file mode 100644
index 0000000..8c32a8c
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/transferCollection.tmpl
@@ -0,0 +1,38 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<title>Koha › Rotating Collections › Transfer Collection</title>
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+
+<div id="main">
+ <h1>Rotating Collections: Transfer Collection</h1>
+ <br />
+ <!-- TMPL_IF NAME="transferSuccess" -->
+ <div>Collection Transfered Successfully</div>
+ <!-- /TMPL_IF -->
+
+ <!-- TMPL_IF NAME="transferFailure" -->
+ <div>Failed to Transfer Collection!</div>
+ <div>Reason: <strong><!-- TMPL_VAR NAME="errorMessage" --></strong></div>
+ <!-- /TMPL_IF -->
+
+ <!-- TMPL_IF NAME="transferSuccess" -->
+ <!-- TMPL_ELSE -->
+ <div>
+ <form action="transferCollection.pl" method="post">
+ <input type="hidden" name="colId" value="<!-- TMPL_VAR NAME="colId" -->">
+
+ <label for="toBranch">Choose your Library:</label>
+ <select name="toBranch">
+ <!-- TMPL_LOOP Name="branchoptionloop" -->
+ <!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR Name="code" -->" selected="selected"><!-- TMPL_VAR Name="name" --></option><!-- TMPL_ELSE --><option value="<!-- TMPL_VAR Name="code" -->"><!-- TMPL_VAR Name="name" --></option><!-- /TMPL_IF -->
+ <!-- /TMPL_LOOP -->
+ </select>
+ <INPUT type="submit" value="Transfer Collection">
+ </form>
+ </div>
+ <!-- /TMPL_IF -->
+ <div>
+ <div><a href="rotatingCollections.pl">Rotating Collections Home</a></div>
+ </div>
+</div>
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
diff --git a/rotating_collections/addItems.pl b/rotating_collections/addItems.pl
new file mode 100755
index 0000000..9a37423
--- /dev/null
+++ b/rotating_collections/addItems.pl
@@ -0,0 +1,82 @@
+#!/usr/bin/perl
+use strict;
+require Exporter;
+
+use C4::Output;
+use C4::Auth;
+use C4::Context;
+use C4::RotatingCollections;
+
+use CGI;
+
+my $query = new CGI;
+my ($template, $loggedinuser, $cookie)
+ = get_template_and_user({template_name => "rotating_collections/addItems.tmpl",
+ query => $query,
+ type => "intranet",
+ authnotrequired => 1,
+ flagsrequired => {parameters => 1},
+ debug => 1,
+ });
+
+if ( $query->param('action') eq 'addItem' ) {
+ ## Add the given item to the collection
+ my $colId = $query->param('colId');
+ my $barcode = $query->param('barcode');
+ my $removeItem = $query->param('removeItem');
+ my $itemnumber = getItemnumberByBarcode( $barcode );
+
+ my ( $success, $errorCode, $errorMessage );
+
+ if ( ! $removeItem ) {
+ ( $success, $errorCode, $errorMessage ) = AddItemToCollection( $colId, $itemnumber );
+
+ $template->param(
+ previousActionAdd => 1,
+ addedBarcode => $barcode,
+ );
+
+ if ( $success ) {
+ $template->param( addSuccess => 1 );
+ } else {
+ $template->param( addFailure => 1 );
+ $template->param( failureMessage => $errorMessage );
+ }
+ } else {
+ ## Remove the given item from the collection
+ ( $success, $errorCode, $errorMessage ) = RemoveItemFromCollection( $colId, $itemnumber );
+
+ $template->param(
+ previousActionRemove => 1,
+ removedBarcode => $barcode,
+ removeChecked => 1,
+ );
+
+ if ( $success ) {
+ $template->param( removeSuccess => 1 );
+ } else {
+ $template->param( removeFailure => 1 );
+ $template->param( failureMessage => $errorMessage );
+ }
+
+ }
+}
+
+my ( $colId, $colTitle, $colDescription, $colBranchcode ) = GetCollection( $query->param('colId') );
+my $collectionItems = GetItemsInCollection( $colId );
+if ( $collectionItems ) {
+ $template->param( collectionItemsLoop => $collectionItems );
+}
+
+$template->param(
+ intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+ intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+ IntranetNav => C4::Context->preference("IntranetNav"),
+
+ colId => $colId,
+ colTitle => $colTitle,
+ colDescription => $colDescription,
+ colBranchcode => $colBranchcode,
+ );
+
+output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/rotating_collections/editCollections.pl b/rotating_collections/editCollections.pl
new file mode 100755
index 0000000..1dba296
--- /dev/null
+++ b/rotating_collections/editCollections.pl
@@ -0,0 +1,103 @@
+#!/usr/bin/perl
+
+use strict;
+require Exporter;
+
+use CGI;
+
+use C4::Output;
+use C4::Auth;
+use C4::Context;
+
+use C4::RotatingCollections;
+
+my $query = new CGI;
+my ($template, $loggedinuser, $cookie)
+ = get_template_and_user({template_name => "rotating_collections/editCollections.tmpl",
+ query => $query,
+ type => "intranet",
+ authnotrequired => 1,
+ flagsrequired => {parameters => 1},
+ debug => 1,
+ });
+
+# Create new Collection
+if ( $query->param('action') eq 'create' ) {
+ my $title = $query->param('title');
+ my $description = $query->param('description');
+
+ my ( $createdSuccessfully, $errorCode, $errorMessage ) = CreateCollection( $title, $description );
+
+ $template->param(
+ previousActionCreate => 1,
+ createdTitle => $title,
+ );
+
+ if ( $createdSuccessfully ) {
+ $template->param( createSuccess => 1 );
+ } else {
+ $template->param( createFailure => 1 );
+ $template->param( failureMessage => $errorMessage );
+ }
+}
+
+## Delete a club or service
+elsif ( $query->param('action') eq 'delete' ) {
+ my $colId = $query->param('colId');
+ my ( $success, $errorCode, $errorMessage ) = DeleteCollection( $colId );
+
+ $template->param( previousActionDelete => 1 );
+ if ( $success ) {
+ $template->param( deleteSuccess => 1 );
+ } else {
+ $template->param( deleteFailure => 1 );
+ $template->param( failureMessage => $errorMessage );
+ }
+}
+
+## Edit a club or service: grab data, put in form.
+elsif ( $query->param('action') eq 'edit' ) {
+ my $colId = $query->param('colId');
+ my ( $colId, $colTitle, $colDesc, $colBranchcode ) = GetCollection( $colId );
+
+ $template->param(
+ previousActionEdit => 1,
+ editColId => $colId,
+ editColTitle => $colTitle,
+ editColDescription => $colDesc,
+ );
+}
+
+# Update a Club or Service
+elsif ( $query->param('action') eq 'update' ) {
+ my $colId = $query->param('colId');
+ my $title = $query->param('title');
+ my $description = $query->param('description');
+
+ my ( $createdSuccessfully, $errorCode, $errorMessage )
+ = UpdateCollection( $colId, $title, $description );
+
+ $template->param(
+ previousActionUpdate => 1,
+ updatedTitle => $title,
+ );
+
+ if ( $createdSuccessfully ) {
+ $template->param( updateSuccess => 1 );
+ } else {
+ $template->param( updateFailure => 1 );
+ $template->param( failureMessage => $errorMessage );
+ }
+}
+
+my $collections = GetCollections();
+
+$template->param(
+ intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+ intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+ IntranetNav => C4::Context->preference("IntranetNav"),
+
+ collectionsLoop => $collections,
+ );
+
+output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/rotating_collections/rotatingCollections.pl b/rotating_collections/rotatingCollections.pl
new file mode 100755
index 0000000..7940ebf
--- /dev/null
+++ b/rotating_collections/rotatingCollections.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+use strict;
+require Exporter;
+
+use CGI;
+
+use C4::Output;
+use C4::Auth;
+use C4::Context;
+use C4::RotatingCollections;
+
+my $query = new CGI;
+my ($template, $loggedinuser, $cookie)
+ = get_template_and_user({template_name => "rotating_collections/rotatingCollections.tmpl",
+ query => $query,
+ type => "intranet",
+ authnotrequired => 1,
+ flagsrequired => {parameters => 1},
+ debug => 1,
+ });
+
+my $branchcode = $query->cookie('branch');
+
+my $collections = GetCollections();
+
+$template->param(
+ intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+ intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+ IntranetNav => C4::Context->preference("IntranetNav"),
+
+ collectionsLoop => $collections,
+ );
+
+output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/rotating_collections/transferCollection.pl b/rotating_collections/transferCollection.pl
new file mode 100755
index 0000000..6ca822c
--- /dev/null
+++ b/rotating_collections/transferCollection.pl
@@ -0,0 +1,66 @@
+#!/usr/bin/perl
+use strict;
+require Exporter;
+
+use C4::Output;
+use C4::Auth;
+use C4::Context;
+use C4::RotatingCollections;
+use C4::Branch;
+
+use CGI;
+
+my $query = new CGI;
+
+my $colId = $query->param('colId');
+my $toBranch = $query->param('toBranch');
+
+my ($template, $loggedinuser, $cookie)
+ = get_template_and_user({template_name => "rotating_collections/transferCollection.tmpl",
+ query => $query,
+ type => "intranet",
+ authnotrequired => 1,
+ flagsrequired => {parameters => 1},
+ debug => 1,
+ });
+
+## Transfer collection
+my ( $success, $errorCode, $errorMessage );
+if ( $toBranch ) {
+ ( $success, $errorCode, $errorMessage ) = TransferCollection( $colId, $toBranch );
+
+ if ( $success ) {
+ $template->param( transferSuccess => 1 );
+ } else {
+ $template->param( transferFailure => 1,
+ errorCode => $errorCode,
+ errorMessage => $errorMessage
+ );
+ }
+}
+
+## Set up the toBranch select options
+my $branches = GetBranches();
+my @branchoptionloop;
+foreach my $br (keys %$branches) {
+ my %branch;
+ $branch{code}=$br;
+ $branch{name}=$branches->{$br}->{'branchname'};
+ push (@branchoptionloop, \%branch);
+}
+
+## Get data about collection
+my ( $colId, $colTitle, $colDesc, $colBranchcode ) = GetCollection( $colId );
+$template->param(
+ intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+ intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+ IntranetNav => C4::Context->preference("IntranetNav"),
+
+ colId => $colId,
+ colTitle => $colTitle,
+ colDesc => $colDesc,
+ colBranchcode => $colBranchcode,
+ branchoptionloop => \@branchoptionloop
+ );
+
+output_html_with_http_headers $query, $cookie, $template->output;
--
1.5.6.5
More information about the Koha-patches
mailing list