my $nb_pages = (@_) ? shift : 1;
my $current_page = (@_) ? shift : undef; # delay default until later
my $startfrom_name = (@_) ? shift : 'page';
+ my $additional_parameters = shift || {};
# how many pages to show before and after the current page?
my $pages_around = 2;
$base_url =~ s/$delim$//; # remove trailing delim
my $url = $base_url . (($base_url =~ m/$delim/ or $base_url =~ m/\?/) ? '&' : '?' ) . $startfrom_name . '=';
+ my $url_suffix;
+ while ( my ( $k, $v ) = each %$additional_parameters ) {
+ $url_suffix .= '&' . $k . '=' . $v;
+ }
my $pagination_bar = '';
# navigation bar useful only if more than one page to display !
"\n" . ' '
. '<a href="'
. $url
- . '1" rel="start">'
+ . '1'
+ . $url_suffix
+ . '"rel="start">'
. '<<' . '</a>';
}
else {
. '<a href="'
. $url
. $previous
+ . $url_suffix
. '" rel="prev">' . '<' . '</a>';
}
else {
"\n" . ' '
. '<a href="'
. $url
- . $page_number . '">'
+ . $page_number
+ . $url_suffix
+ . '">'
. $page_number . '</a>';
}
$last_displayed_page = $page_number;
. ' <a href="'
. $url
. $next
+ . $url_suffix
. '" rel="next">' . '>' . '</a>';
}
else {
. ' <a href="'
. $url
. $nb_pages
+ . $url_suffix
. '" rel="last">'
. '>>' . '</a>';
}
use C4::Context;
use C4::Members qw/GetMemberIssuesAndFines/;
use C4::Utils::DataTables;
-use C4::VirtualShelves;
+use Koha::Virtualshelves;
sub search {
my ( $params ) = @_;
( $iTotalRecords ) = $dbh->selectrow_array( $query, undef, @args );
for my $shelf ( @$shelves ) {
- $shelf->{can_manage_shelf} = C4::VirtualShelves::ShelfPossibleAction( $loggedinuser, $shelf->{shelfnumber}, 'manage' );
- $shelf->{can_delete_shelf} = C4::VirtualShelves::ShelfPossibleAction( $loggedinuser, $shelf->{shelfnumber}, 'delete_shelf' );
+ my $s = Koha::Virtualshelves->find( $shelf->{shelfnumber} );
+ $shelf->{can_manage_shelf} = $s->can_be_managed( $loggedinuser );
+ $shelf->{can_delete_shelf} = $s->can_be_deleted( $loggedinuser );
}
return {
iTotalRecords => $iTotalRecords,
loggedinuser => $loggedinuser,
OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
);
- my $edit;
my $shelves;
my @paramsloop;
my $totitems;
my $shelf = Koha::Virtualshelves->find( $shelfnumber );
my $member = GetMember( 'borrowernumber' => $shelf->owner );
my $ownername = defined($member) ? $member->{firstname} . " " . $member->{surname} : '';
- $edit = 1;
$template->param(
edit => 1,
display => $displaymode,
#View a shelf
if ( $shelfnumber = $query->param('viewshelf') ) {
my $shelf = Koha::Virtualshelves->find( $shelfnumber );
- $template->param(
- 'DisplayMultiPlaceHold' => C4::Context->preference('DisplayMultiPlaceHold'),
- );
if (C4::Context->preference('TagsEnabled')) {
$template->param(TagsEnabled => 1);
foreach (qw(TagsShowOnList TagsInputOnList)) {
csv_profiles => GetCsvProfilesLoop('marc')
);
- unless( $shelfnumber or $shelves or $edit ) {
- # Only used for intranet
- $template->param( op => 'list' );
- }
-
- if ($shelves or # note: this part looks duplicative, but is intentional
- $edit
- ) {
- $template->param( seflag => 1 );
- #This hack is just another argument for refactoring this script one day
- #At this point you are adding or editing a list; if you add, then you add a private list (by default) with permissions as below; if you edit, do not pass these permissions, they must come from the database
- $template->param( allow_add => 0, allow_delete_own => 1, allow_delete_other => 0) unless $shelfnumber;
- }
-
#Next call updates the shelves for the Lists button.
#May not always be needed (when nothing changed), but doesn't take much.
my ($total, $pubshelves, $barshelves) = C4::VirtualShelves::GetSomeShelfNames($loggedinuser, 'MASTHEAD');
use Carp;
+use C4::Auth;
+
+use Koha::Borrowers;
use Koha::Database;
use Koha::DateUtils qw( dt_from_string );
use Koha::Exceptions;
return $number_removed;
}
+sub can_be_viewed {
+ my ( $self, $borrowernumber ) = @_;
+ return 1 if $self->category == $PUBLIC;
+ return 0 unless $borrowernumber;
+ return 1 if $self->owner == $borrowernumber;
+ return $self->get_shares->search(
+ {
+ borrowernumber => $borrowernumber,
+ }
+ )->count;
+}
+
+sub can_be_deleted {
+ my ( $self, $borrowernumber ) = @_;
+
+ return 0 unless $borrowernumber;
+ return 1 if $self->owner == $borrowernumber;
+
+ my $patron = Koha::Borrowers->find( $borrowernumber );
+
+ return 1 if $self->category == $PUBLIC and C4::Auth::haspermission( $patron->userid, { lists => 'delete_public_lists' } );
+
+ return 0;
+}
+
+sub can_be_managed {
+ my ( $self, $borrowernumber ) = @_;
+ return 1
+ if $borrowernumber and $self->owner == $borrowernumber;
+ return 0;
+}
+
+sub can_biblios_be_added {
+ my ( $self, $borrowernumber ) = @_;
+
+ return 1
+ if $borrowernumber
+ and ( $self->owner == $borrowernumber
+ or $self->allow_add );
+ return 0;
+}
+
+sub can_biblios_be_removed {
+ my ( $self, $borrowernumber ) = @_;
+
+ return 1
+ if $borrowernumber
+ and ( $self->owner == $borrowernumber
+ or $self->allow_delete_own
+ or $self->allow_delete_other );
+ return 0;
+}
+
sub type {
return 'Virtualshelve';
}
<script type="text/javascript">
//<![CDATA[
-[% IF ( viewshelf ) %]
+[% IF op == 'view' %]
function sendList(){
open(CGIBIN+'virtualshelves/sendshelf.pl?shelfid=[% shelfnumber %]','win_form','scrollbars=no,resizable=no,height=300,width=450,top=50,left=100');
return false;
});
$("#deleteshelf").click(function(e){
- if(confirmDelete(_("Are you sure you want to delete this list?"))){
+ if(confirm(_("Are you sure you want to delete this list?"))){
return true;
} else {
e.preventDefault();
</script>
<div id="toolbar" class="btn-toolbar">
- <div class="btn-group"><a id="newshelf" class="btn btn-small" href="/cgi-bin/koha/virtualshelves/shelves.pl?shelves=1"><i class="fa fa-plus"></i> New list</a></div>
+ <div class="btn-group"><a id="newshelf" class="btn btn-small" href="/cgi-bin/koha/virtualshelves/shelves.pl?op=add_form&referer=[% op %]"><i class="fa fa-plus"></i> New list</a></div>
- [% IF ( viewshelf ) %]
- [% IF ( manageshelf ) %]
+ [% IF op == 'view' %]
+ [% IF can_manage_shelf %]
<div class="btn-group">
<button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><i class="fa fa-pencil"></i> Edit <span class="caret"></span></button>
- <ul class="dropdown-menu">
- <li><a href="/cgi-bin/koha/virtualshelves/shelves.pl?shelfnumber=[% shelfnumber %]&op=modif&display=viewshelf">Edit list</a></li>
- [% IF ( showprivateshelves ) %]
- <li><a id="deleteshelf" href="/cgi-bin/koha/virtualshelves/shelves.pl?display=privateshelves&shelves=1&DEL-[% shelfnumber %]=1">Delete list</a></li>
- [% ELSE %]
- <li><a id="deleteshelf" href="/cgi-bin/koha/virtualshelves/shelves.pl?shelves=1&DEL-[% shelfnumber %]=1">Delete list</a></li>
- [% END %]
- </ul>
+ <ul class="dropdown-menu">
+ <li><a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=edit_form&shelfnumber=[% shelf.shelfnumber %]&referer=[% op %]">Edit list</a></li>
+ <li><a id="deleteshelf" href="/cgi-bin/koha/virtualshelves/shelves.pl?op=delete&shelfnumber=[% shelf.shelfnumber %]">Delete list</a></li>
+ </ul>
</div>
[% END %]
</ul>
</div>
<div class="btn-group"><a class="btn btn-small" href="#" id="sendlist"><i class="fa fa-envelope"></i> Send list</a></div>
- <div class="btn-group"><a class="btn btn-small" id="printlist" target="_blank" href="/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=[% shelfnumber %]&print=1"><i class="fa fa-print"></i> Print list</a></div>
+ <div class="btn-group"><a class="btn btn-small" id="printlist" target="_blank" href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&shelfnumber=[% shelf.shelfnumber %]&print=1"><i class="fa fa-print"></i> Print list</a></div>
[% END %]
</div>
[% IF ( GetShelves ) %]
<span class="results_summary"><span class="label">Lists that include this title: </span>
[% FOREACH GetShelve IN GetShelves %]
- <a href="/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=[% GetShelve.shelfnumber %]">[% GetShelve.shelfname %]</a>
+ <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&shelfnumber=[% GetShelve.shelfnumber %]">[% GetShelve.shelfname %]</a>
[% IF ( loop.last ) %][% ELSE %]|[% END %]
[% END %]
</span>
<li><strong>Lists that include this title: </strong>
<ul>
[% FOREACH GetShelve IN GetShelves %]
- <li><a href="/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=[% GetShelve.shelfnumber %]">[% GetShelve.shelfname %]</a></li>
+ <li><a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&shelfnumber=[% GetShelve.shelfnumber %]">[% GetShelve.shelfname %]</a></li>
[% END %]
</ul>
</li>
[% INCLUDE 'doc-head-close.inc' %]
</head>
<body id="lists_downloadshelf" class="lists" style="padding:1em;">
+
+[% FOR m IN messages %]
+ <div class="dialog [% m.type %]">
+ [% SWITCH m.code %]
+ [% CASE 'unauthorized' %]
+ You do not have permission to view this list.
+ [% CASE 'does_not_exist' %]
+ This list does not exist.
+ [% CASE %]
+ [% m.code %]
+ [% END %]
+ </div>
+[% END %]
+
+
+
[% IF ( format ) %]
<p>Your download should begin automatically.</p>
[% ELSE %]
+[% USE Koha %]
+[% USE KohaDates %]
+[% SET PRIVATE = 1 %]
+[% SET PUBLIC = 2 %]
[% INCLUDE 'doc-head-open.inc' %]
-<title>Koha › [% IF ( viewshelf ) %]Lists › Contents of [% shelfname | html %][% ELSE %]Lists[% END %][% IF ( shelves ) %] › Create new list[% END %][% IF ( edit ) %] › Edit list [% shelfname | html %][% END %]</title>
+<title>Koha › [% IF op == 'view' %]Lists › Contents of [% shelf.shelfname | html %][% ELSE %]Lists[% END %][% IF op == 'add_form' %] › Create new list[% END %][% IF op == 'edit_form' %] › Edit list [% shelf.shelfname | html %][% END %]</title>
[% INCLUDE 'doc-head-close.inc' %]
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
[% INCLUDE 'datatables.inc' %]
</script>
[% END %]
-[% IF ( viewshelf ) %]
+[% IF op == 'view' %]
<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.fixFloat.js"></script>
[% END %]
[% IF op == 'list' %]
$(document).ready(function(){
- var type = 1;
+ [% IF category == PUBLIC %]
+ var type = [% PUBLIC %];
+ [% ELSE %]
+ var type = [% PRIVATE %];
+ [% END %]
var dtListResults = $("#listresultst").dataTable($.extend(true, {}, dataTablesDefaults, {
'bServerSide': true,
'sAjaxSource': "/cgi-bin/koha/svc/virtualshelves/search",
dtListResults.fnAddFilters("filter", 750);
var tabs = $("#tabs").tabs({
+ [% IF category == PUBLIC %]
+ active: 1,
+ [% ELSE %]
+ active: 0,
+ [% END %]
activate: function(e, ui) {
var active = tabs.tabs("option", "active" );
if ( active == 0 ) {
- type = 1; // private
+ type = [% PRIVATE %];
dtListResults.fnDraw();
} else if ( active == 1 ) {
- type = 2; // public
+ type = [% PUBLIC %];
dtListResults.fnDraw();
}
}
});
[% END %]
-[% IF ( viewshelf ) %]
+[% IF op == 'view' %]
$(document).ready(function(){
[% IF ( itemsloop ) %]$('#searchheader').fixFloat();[% END %]
$("span.clearall").html("<a id=\"CheckNone\" href=\"/cgi-bin/koha/shelves.pl\">"+_("Clear all")+"<\/a>");
});
[% END %]
- function confirmDelete(message){
- if (window.confirm(message)) {
- location.href="/cgi-bin/koha/virtualshelves/shelves.pl?[% IF ( showprivateshelves ) %]display=privateshelves&[% END %]shelves=1&DEL-[% shelfnumber %]=1&shelfoff=[% shelfoff %]";
- } else {
- return false;
- }
- }
-
/**
* This function checks if the adequate number of records are checked for merging
*/
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
-[% BLOCK list_permissions %]
- <li>
- <label for="permissions">Permissions: </label>
- <select name="allow_add" id="allow_add">
- [% IF allow_add %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
- [% IF allow_add %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
- </select>
- <span>anyone else to add entries.</span>
- </li>
- <li>
- <label> </label>
- <select name="allow_delete_own" id="allow_delete_own">
- [% IF allow_delete_own %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
- [% IF allow_delete_own %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
- </select>
- <span>anyone to remove his own contributed entries.</span>
- </li>
- <li>
- <label> </label>
- <select name="allow_delete_other" id="allow_delete_other">
- [% IF allow_delete_other %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
- [% IF allow_delete_other %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
- </select>
- <span>anyone to remove other contributed entries.</span>
- </li>
-[% END %]
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/virtualshelves/shelves.pl">Lists</a> [% IF ( category1 ) %] › [% IF ( viewshelf || edit ) %] <a href="/cgi-bin/koha/virtualshelves/shelves.pl?display=privateshelves">Your lists</a> [% ELSE %] Your lists [% END %] [% ELSIF ( category2 ) %] › [% IF ( viewshelf ) %] <a href="/cgi-bin/koha/virtualshelves/shelves.pl?display=publicshelves">Public lists</a> [% ELSE %] Public lists [% END %] [% ELSIF ( showprivateshelves ) %] › [% IF ( viewshelf || edit ) %] <a href="/cgi-bin/koha/virtualshelves/shelves.pl?display=privateshelves">Your lists</a> [% ELSE %] Your lists [% END %] [% ELSIF ( showpublicshelves ) %] › [% IF ( viewshelf || edit ) %] <a href="/cgi-bin/koha/virtualshelves/shelves.pl?display=publicshelves">Public lists</a> [% ELSE %] Public lists [% END %] [% END %]
+<div id="breadcrumbs">
+ <a href="/cgi-bin/koha/mainpage.pl">Home</a> ›
+ [% IF op != 'list' %]
+ <a href="/cgi-bin/koha/virtualshelves/shelves.pl">Lists</a>
+ [% ELSE %]
+ Lists
+ [% END %]
+ [% IF shelf AND shelf.category == PRIVATE %] ›
+ [% IF op == 'view' OR op == 'edit_form' %]
+ <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&category=[% PRIVATE %]">Your lists</a>
+ [% ELSE %]
+ Your lists
+ [% END %]
+ [% ELSIF shelf AND shelf.category == PUBLIC %] ›
+ [% IF op == 'view' %]
+ <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&category=[% PUBLIC %]">Public lists</a>
+ [% ELSE %]
+ Public lists
+ [% END %]
+ [% END %]
-[% IF ( viewshelf ) %]› Contents of <i>[% shelfname | html %]</i>[% END %][% IF ( shelves ) %] › Create new list[% END %][% IF ( edit ) %] › Edit list <i>[% shelfname | html %]</i>[% END %]</div>
+[% IF op == 'view' %]› Contents of <i>[% shelf.shelfname | html %]</i>[% END %][% IF op == 'add_form' %] › Create new list[% END %][% IF op == 'edit_form' %] › Edit list <i>[% shelf.shelfname | html %]</i>[% END %]</div>
<div id="doc3" class="yui-t2">
<div id="bd">
[% CASE 'error_on_insert' %]
An error occurred when inserting this list. Perhaps the name already exists.
[% CASE 'error_on_delete' %]
- An error occurred when deleteing this list. Check the logs.
+ An error occurred when deleting this list. Check the logs.
+ [% CASE 'error_on_add_biblio' %]
+ The item has not been added to the list. Please check it's not in this list yet.
[% CASE 'success_on_update' %]
List updated with success.
[% CASE 'success_on_insert' %]
List inserted with success.
[% CASE 'success_on_delete' %]
List deleted with success.
- [% CASE 'Koha::Exception::DuplicateObject' %]
+ [% CASE 'success_on_add_biblio' %]
+ The item has been added to the list.
+ [% CASE 'success_on_remove_biblios' %]
+ The item has been removed from the list.
+ [% CASE 'does_not_exist' %]
+ This list does not exist.
+ [% CASE 'item_does_not_exist' %]
+ This item does not exist.
+ [% CASE 'unauthorized_on_view' %]
+ You do not have permission to view this list.
+ [% CASE 'unauthorized_on_update' %]
+ You do not have permission to update this list.
+ [% CASE 'unauthorized_on_delete' %]
+ You do not have permission to delete this list.
+ [% CASE 'unauthorized_on_add_biblio' %]
+ You do not have permission to add a biblio to this list.
+ [% CASE 'no_biblio_removed' %]
+ No biblio has been removed.
+ [% CASE 'Koha::Exceptions::Virtualshelves::DuplicateObject' %]
An error occurred when inserting this list. The name already [% shelfname %] exists.
+ [% CASE 'DBIx::Class::Exception' %]
+ [% m.msg %]
[% CASE %]
[% m.code %]
[% END %]
</div>
[% END %]
-[% IF ( paramsloop ) %]
-[% FOREACH paramsloo IN paramsloop %]
-<div class="yui-ge">
- <div class="yui-u first">
- [% IF ( paramsloo.status ) %]<div class="dialog alert">[% paramsloo.string %]</div>[% END %]
- [% IF ( paramsloo.nobarcode ) %]<div class="dialog alert">ERROR: No barcode given.</div>[% END %]
- [% IF ( paramsloo.noshelfnumber ) %]<div class="dialog alert">ERROR: No list number given.</div>[% END %]
- [% IF ( paramsloo.need_confirm ) %]
- <div class="dialog alert">The list <i>[% paramsloo.need_confirm %]</i> is not empty.
- [% IF ( paramsloo.single ) %]
- <br />It has <b>[% paramsloo.count %]</b> entry.
- [% ELSE %]
- <br />It has <b>[% paramsloo.count %]</b> entries.
- [% END %]
- <br />Use the "Confirm" button below to confirm deletion.
- </div>
- [% END %]
- [% IF ( paramsloo.nopermission ) %]
- <div class="dialog alert">ERROR: You do not have adequate permission for that action on list [% paramsloo.nopermission %].</div>
- [% END %]
- [% IF ( paramsloo.failgetitem ) %]
- <div class="dialog alert">ERROR: No item found with barcode [% paramsloo.failgetitem %].</div>
- [% END %]
- [% IF ( paramsloo.duplicatebiblio ) %]
- <div class="dialog alert">A record matching barcode <b>[% paramsloo.duplicatebiblio %]</b> has already been added.</div>
- [% END %]
- [% IF ( paramsloo.nothingdeleted) %]
- <div class="dialog message">Warning: You could not delete any of the selected items from this list.</div>
- [% END %]
- [% IF ( paramsloo.somedeleted) %]
- <div class="dialog message">Warning: You could not delete all selected items from this list.</div>
- [% END %]
- [% IF ( paramsloo.modifyfailure) %]
- <div class="dialog message">ERROR: List could not be modified.</div>
- [% END %]
- </div>
-</div>
-[% END %]
-[% END %]
-
-[% IF ( viewshelf ) %]
+[% IF op == 'view' %]
<div class="yui-g">
- [% IF ( itemsloop ) %]
+ [% IF itemsloop %]
- <h3>Contents of <i>[% shelfname | html %]</i></h3>
+ <h3>Contents of <i>[% shelf.shelfname | html %]</i></h3>
<div class="pages">[% pagination_bar %]</div>
<form action="/cgi-bin/koha/virtualshelves/shelves.pl" id="listform" method="post" class="checkboxed">
- <input type="hidden" name="viewshelf" value="[% shelfnumber %]" />
- <input type="hidden" name="modifyshelfcontents" value="1" />
+ <input type="hidden" name="op" value="remove_biblios" />
+ <input type="hidden" name="referer" value="view" />
+ <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber %]" />
[% IF direction == 'asc' %]
[% SET new_direction = 'desc' %]
[% END %]
<div id="searchheader" class="noprint">
- [% IF ( itemsloop ) %]
+ [% IF itemsloop %]
<div id="selection_ops"><span class="checkall"></span> |
<span class="clearall"></span>
<span class="addto">| </span>
- [% IF ( CAN_user_reserveforothers && DisplayMultiPlaceHold ) %]
+ [% IF CAN_user_reserveforothers && Koha.Preference('DisplayMultiPlaceHold') %]
<div class="btn-group"><button class="btn btn-mini placehold"><i class="fa fa-sticky-note-o"></i> Place hold</button></div>
[% END %]
- [% IF ( allowremovingitems ) %]
+ [% IF can_remove_biblios %]
<div class="btn-group"><button type="submit" class="btn btn-mini list-remove"><i class="fa fa-times-circle"></i> Remove selected</button></div>
[% END %]
[% IF ( CAN_user_editcatalogue_edit_catalogue ) %]<div class="btn-group"><button type="submit" class="btn btn-mini merge-items"><i class="fa fa-compress"></i> Merge selected</button></div>[% END %]
[% UNLESS ( item_level_itypes ) %]<th>Item type</th>[% END %]
<th>
- <a href="/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=[% shelfnumber %]&sort=title&direction=[% IF sort != 'title' %]asc[% ELSE %][% new_direction %][% END %]">Title</a>
- [% IF sort == 'title' %]
+ <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&shelfnumber=[% shelf.shelfnumber %]&sortfield=title&direction=[% IF sortfield != 'title' %]asc[% ELSE %][% new_direction %][% END %]">Title</a>
+ [% IF sortfield == 'title' %]
<img src="[% interface %]/[% theme %]/img/[% direction %].gif" alt="[% direction %] sort" />
[% ELSE %]
<img src="[% interface %]/[% theme %]/img/ascdesc.gif" alt="" />
[% END %]
</th>
<th>
- <a href="/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=[% shelfnumber %]&sort=author&direction=[% IF sort != 'author' %]asc[% ELSE %][% new_direction %][% END %]">Author</a>
- [% IF sort == 'author' %]
+ <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&shelfnumber=[% shelf.shelfnumber %]&sortfield=author&direction=[% IF sortfield != 'author' %]asc[% ELSE %][% new_direction %][% END %]">Author</a>
+ [% IF sortfield == 'author' %]
<img src="[% interface %]/[% theme %]/img/[% direction %].gif" alt="[% direction %] sort" />
[% ELSE %]
<img src="[% interface %]/[% theme %]/img/ascdesc.gif" alt="" />
</th>
<th>Date added</th>
<th>
- <a href="/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=[% shelfnumber %]&sort=itemcallnumber&direction=[% IF sort != 'itemcallnumber' %]asc[% ELSE %][% new_direction %][% END %]">Call number</a>
- [% IF sort == 'itemcallnumber' %]
+ <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&shelfnumber=[% shelf.shelfnumber %]&sortfield=itemcallnumber&direction=[% IF sortfield != 'itemcallnumber' %]asc[% ELSE %][% new_direction %][% END %]">Call number</a>
+ [% IF sortfield == 'itemcallnumber' %]
<img src="[% interface %]/[% theme %]/img/[% direction %].gif" alt="[% direction %] sort" />
[% ELSE %]
<img src="[% interface %]/[% theme %]/img/ascdesc.gif" alt="" />
[% END %]
</th>
</tr>
- [% FOREACH itemsloo IN itemsloop %]
- [% UNLESS ( loop.odd ) %]
- <tr class="highlight">
- [% ELSE %]
- <tr>
- [% END %]
- [% IF ( itemsloop ) %]
- <td>
- [% IF ( itemsloo.confirm ) %]
- <input type="hidden" name="CONFIRM-[% itemsloo.confirm %]" />
- <input type="checkbox" class="selection" value="[% itemsloo.biblionumber %]" name="REM-[% itemsloo.biblionumber %]" checked />
- [% ELSE %]
- <input type="checkbox" class="selection" value="[% itemsloo.biblionumber %]" name="REM-[% itemsloo.biblionumber %]" />
- [% END %]
- </td>
- [% END %]
+ [% FOREACH itemsloo IN itemsloop %]
+ [% UNLESS ( loop.odd ) %]
+ <tr class="highlight">
+ [% ELSE %]
+ <tr>
+ [% END %]
+ [% IF itemsloop %]
+ <td>
+ <input type="checkbox" class="selection" value="[% itemsloo.biblionumber %]" name="biblionumber" />
+ </td>
+ [% END %]
[% UNLESS ( item_level_itypes ) %]<td>
[% UNLESS ( noItemTypeImages || !itemsloo.imageurl ) %]<img src="[% itemsloo.imageurl %]" alt="[% itemsloo.description %]" title="[% itemsloo.description %]" />[% END %][% itemsloo.description %]
</td>[% END %]
| <a href="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% itemsloo.biblionumber %]">Edit items</a>
[% END %]
</p>
- </td>
- <td>[% itemsloo.author %]</td>
- <td>[% itemsloo.dateadded %]</td>
- <td>
+ </td>
+ <td>[% itemsloo.author %]</td>
+ <td>[% itemsloo.dateadded | $KohaDates%]</td>
+ <td>
<ul>
[% FOREACH result IN itemsloo.ITEM_RESULTS %]
<li>[% result.holdingbranch %] [% IF ( result.location_intranet ) %] ([% result.location_intranet %]) [% END %]
[% END %]
</div>
-[% END %]<!-- /viewshelf -->
+[% END %]
-[% IF ( debug ) %]
- [% IF ( edit ) %]<div>Edit is on ([% shelfname | html %])</div>[% END %]
- [% IF ( seflag ) %]<div>seflag is on ([% seflag %])</div>[% END %]
+[% IF can_add_biblios %]
+<div class="yui-g">
+<form action="/cgi-bin/koha/virtualshelves/shelves.pl" method="post">
+ <fieldset class="brief noprint">
+ <legend>Add an item to <i>[% shelfname | html %]</i></legend>
+ <ol>
+ <li>
+ <label for="barcode">Barcode:</label>
+ <input name="barcode" type="text" id="barcode" size="14" />
+ <input type="hidden" name="op" value="add_biblio" />
+ <input type="hidden" name="referer" value="view" />
+ <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber %]" />
+ <input type="submit" value="Add" />
+ </li>
+ </ol>
+ </fieldset>
+</form>
+</div>
[% END %]
-[% IF ( seflag ) %]
+[% IF op == 'add_form' OR op == 'edit_form' %]
<div class="yui-ge">
<div class="yui-u first">
<form method="post" action="/cgi-bin/koha/virtualshelves/shelves.pl" class="validated">
<fieldset class="rows">
- [% IF ( shelves ) %]
- <legend>Create a new list</legend>
- <input type="hidden" name="shelves" value="1" />
+ [% IF op == 'add_form' %]
+ <legend>Create a new list</legend>
+ <input type="hidden" name="op" value="add" />
+ [% ELSE %]
+ <legend>Edit list <i>[% shelf.shelfname | html %]</i></legend>
+ <input type="hidden" name="op" value="edit" />
+ [% END %]
+ <input type="hidden" name="referer" value="[% referer %]" />
+ <input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber %]" />
<ol>
- <li><label class="required" for="addshelf">List name:</label><input id="addshelf" type="text" name="addshelf" size="25" required="required" class="required" />
+ <li>
+ <label for="shelfname" class="required">Name: </label><input type="text" id="shelfname" name="shelfname" size="25" value="[% shelf.shelfname |html %]" required="required" class="required" />
<span class="required">Required</span>
- </li>
- <li><span class="label">Owner: </span><input type="hidden" name="owner" id="owner" value="[% loggedinuser %]" />[% loggedinusername %]</li>
- <li><label for="sortfield" >Sort this list by: </label>
- <select name="sortfield" id="sortfield">
- <option value="title">Title</option>
- <option value="author">Author</option>
- <option value="copyrightdate">Copyrightdate</option>
- <option value="itemcallnumber">Call number</option>
- </select></li>
- <li><label for="category">Category: </label>
- <select name="category" id="category">
- <option value="1">Private</option>
- <option value="2">Public</option>
- </select></li>
- [% INCLUDE list_permissions %]
- </ol>
- [% END %]
-
- [% IF ( edit ) %]
- <legend>Edit list <i>[% shelfname | html %]</i></legend>
- <input type="hidden" name="display" value="[% display %]" />
- <input type="hidden" name="op" value="modifsave" />
- [% IF ( showprivateshelves ) %]<input type="hidden" name="display" value="privateshelves" />[% END %]
- <input type="hidden" name="shelfnumber" value="[% shelfnumber %]" />
- <ol>
- <li><label for="shelfname" class="required">Name: </label><input type="text" id="shelfname" name="shelfname" size="25" value="[% shelfname |html %]" required="required" class="required" />
- <span class="required">Required</span>
- </li>
- <li><label for="owner">Owner: </label><input type="hidden" id="owner" name="owner" value="[% IF ( owner ) %][% ownername %][% ELSE %][% loggedinusername %][% END %]" />[% IF ( owner ) %][% ownername %][% ELSE %][% loggedinusername %][% END %]</li>
- <li><label for="sortfield" >Sort this list by: </label>
- <select name="sortfield">
- [% IF ( sortfield == "title" ) %]<option value="title" selected="selected">Title</option>[% ELSE %]<option value="title">Title</option>[% END %]
- [% IF ( sortfield == "author" ) %]<option value="author" selected="selected">Author</option>[% ELSE %]<option value="author">Author</option>[% END %]
- [% IF ( sortfield == "copyrightdate" ) %]<option value="copyrightdate" selected="selected">Copyrightdate</option>[% ELSE %]<option value="copyrightdate">Copyrightdate</option>[% END %]
- [% IF ( sortfield == "itemcallnumber" ) %]<option value="itemcallnumber" selected="selected">Call number</option>[% ELSE %]<option value="itemcallnumber">Call number</option>[% END %]
- </select></li>
- <li><label for="category">Category: </label>
- <select id="category" name="category">
- [% IF ( category1 ) %]
- <option value="1" selected="selected">Private</option>
- [% ELSE %]
- <option value="1">Private</option>
- [% END %]
- [% IF ( category2 ) %]
- <option value="2" selected="selected">Public</option>
- [% ELSE %]
- <option value="2">Public</option>
- [% END %]
- </select></li>
- [% INCLUDE list_permissions %]
- </ol>
- [% END %]
+ </li>
+ <li>
+ <span class="label">Owner: </span>
+ [% IF op == 'add_form' %]
+ <input type="hidden" name="owner" id="owner" value="[% loggedinusernumber %]" />[% loggedinusername %]</li>
+ [% ELSE %]
+ [% IF owner %]
+ <input type="hidden" id="owner" name="owner" value="[% owner.borrowernumber %]" />[% owner.firstname _ ' ' _ owner.surname %]
+ [% ELSE %]
+ <input type="hidden" id="owner" name="owner" value="[% loggedinusernumber %]" />[% loggedinusername %]
+ [% END %]
+ [% END %]
+ </li>
+ <li><label for="sortfield" >Sort this list by: </label>
+ <select name="sortfield">
+ [% IF shelf.sortfield == "title" %]<option value="title" selected="selected">Title</option>[% ELSE %]<option value="title">Title</option>[% END %]
+ [% IF shelf.sortfield == "author" %]<option value="author" selected="selected">Author</option>[% ELSE %]<option value="author">Author</option>[% END %]
+ [% IF shelf.sortfield == "copyrightdate" %]<option value="copyrightdate" selected="selected">Copyrightdate</option>[% ELSE %]<option value="copyrightdate">Copyrightdate</option>[% END %]
+ [% IF shelf.sortfield == "itemcallnumber" %]<option value="itemcallnumber" selected="selected">Call number</option>[% ELSE %]<option value="itemcallnumber">Call number</option>[% END %]
+ </select></li>
+ <li><label for="category">Category: </label>
+ <select id="category" name="category">
+ [% IF shelf.category == PRIVATE %]
+ <option value="1" selected="selected">Private</option>
+ [% ELSE %]
+ <option value="1">Private</option>
+ [% END %]
+ [% IF shelf.category == PUBLIC %]
+ <option value="2" selected="selected">Public</option>
+ [% ELSE %]
+ <option value="2">Public</option>
+ [% END %]
+ </select></li>
- </fieldset>
+ [% FOR permission IN ['allow_add', 'allow_delete_own', 'allow_delete_other'] %]
+ <li>
+ [% IF loop.first %]
+ <label for="permissions">Permissions: </label>
+ [% ELSE %]
+ <label> </label>
+ [% END %]
+ <select name="[% permission %]" id="[% permission %]">
+ [% IF shelf.$permission %]<option value="0">Do not allow</option>[% ELSE %]<option value="0" selected="selected">Do not allow</option>[% END %]
+ [% IF shelf.$permission %]<option value="1" selected="selected">Allow</option>[% ELSE %]<option value="1">Allow</option>[% END %]
+ </select>
+ [% SWITCH permission %]
+ [% CASE 'allow_add' %] <span>anyone else to add entries.</span>
+ [% CASE 'allow_delete_own' %] <span>anyone to remove his own contributed entries.</span>
+ [% CASE 'allow_delete_other' %] <span>anyone to remove other contributed entries.</span>
+ [% END %]
+ </li>
+ [% END %]
+ </ol>
+ </fieldset>
- <fieldset class="action"><input type="submit" value="Save" class="submit" />
- [% IF ( showprivateshelves ) %]
- <a href="/cgi-bin/koha/virtualshelves/shelves.pl?display=privateshelves" class="cancel">Cancel</a>
- [% ELSE %]
- [% IF ( display == "viewshelf" ) %]
- <a href="/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=[% shelfnumber %]" class="cancel">Cancel</a>
+ <fieldset class="action">
+ <input type="submit" value="Save" class="submit" />
+ [% IF referer == 'view' %]
+ <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=view&shelfnumber=[% shelf.shelfnumber %]" class="cancel">Cancel</a>
+ [% ELSE %]
+ [% IF category == PUBLIC %]
+ <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&category=[% PUBLIC %]" class="cancel">Cancel</a>
[% ELSE %]
- <a href="/cgi-bin/koha/virtualshelves/shelves.pl" class="cancel">Cancel</a>
+ <a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=list&category=[% PRIVATE %]" class="cancel">Cancel</a>
[% END %]
[% END %]
</fieldset>
</div>
</div>
</div>
-[% END %]<!-- /seflag -->
+[% END %]
[% IF op == 'list' %]
<h2>Lists</h2>
"dt_type":
"[% data.type %]",
"dt_shelfname":
- "<a href='/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=[% data.shelfnumber %]'>[% data.shelfname | html%]</a>",
+ "<a href='/cgi-bin/koha/virtualshelves/shelves.pl?op=view&shelfnumber=[% data.shelfnumber %]'>[% data.shelfname | html%]</a>",
"dt_count":
"[% data.count %] item(s)",
"dt_owner":
[%~ IF can_manage_shelf ~%]
[%~ action_block = '<form action="shelves.pl" method="get">' ~%]
[%~ action_block = action_block _ '<input type="hidden" name="shelfnumber" value="' _ shelfnumber _ '" />' ~%]
- [%~ action_block = action_block _ '<input type="hidden" name="op" value="modif" />' ~%]
+ [%~ action_block = action_block _ '<input type="hidden" name="op" value="edit_form" />' ~%]
+ [%~ action_block = action_block _ '<input type="hidden" name="category" value="' _ type _ '" />' ~%]
[%~ action_block = action_block _ '<input type="submit" class="editshelf" value="Edit" />' ~%]
[%~ action_block = action_block _ '</form>' ~%]
[%~ END ~%]
[%~ action_block = action_block _ '<form action="shelves.pl" method="post">' ~%]
[%~ action_block = action_block _ '<input type="hidden" name="shelfoff" value="' _ shelfoff _ '" />' ~%]
[%~ action_block = action_block _ '<input type="hidden" name="shelves" value="1" />' ~%]
- [%~ action_block = action_block _ '<input type="hidden" name="DEL-' _ shelfnumber _ '" value="1" />' ~%]
- [%~ action_block = action_block _ '<input type="hidden" name="CONFIRM-' _ shelfnumber _ '" value="1" />' ~%]
- [%~ IF type == 1 ~%]
- [%~ action_block = action_block _ '<input type="hidden" name="display" value="privateshelves" />' ~%]
- [%~ ELSE ~%]
- [%~ action_block = action_block _ '<input type="hidden" name="display" value="publicshelves" />' ~%]
- [%~ END ~%]
+ [%~ action_block = action_block _ '<input type="hidden" name="op" value="delete" />' ~%]
+ [%~ action_block = action_block _ '<input type="hidden" name="shelfnumber" value="' _ shelfnumber _ '" />' ~%]
+ [%~ action_block = action_block _ '<input type="hidden" name="category" value="' _ type _ '" />' ~%]
[%~ action_block = action_block _ '<input type="submit" class="deleteshelf" onclick="return confirmDelete(MSG_CONFIRM_DELETE_LIST)" value="Delete" />' ~%]
[%~ action_block = action_block _ '</form>' ~%]
[%~ END ~%]
#!/usr/bin/perl
use Modern::Perl;
-use Test::More tests => 3;
+use Test::More tests => 4;
use DateTime::Duration;
use C4::Context;
$number_of_contents = Koha::Virtualshelfcontents->search->count;
is( $number_of_contents, 1, 'The biblio should have been deleted to the shelf by the patron 2, even if it is not his own content (allow_delete_other=1)' );
};
+
+subtest 'Shelf permissions' => sub {
+
+ plan tests => 40;
+ my $patron1 = $builder->build( { source => 'Borrower', value => { flags => '2096766' } } ); # 2096766 is everything checked but not superlibrarian
+ my $patron2 = $builder->build( { source => 'Borrower', value => { flags => '1048190' } } ); # 1048190 is everything checked but not superlibrarian and delete_public_lists
+ my $biblio1 = $builder->build( { source => 'Biblio', } );
+ my $biblio2 = $builder->build( { source => 'Biblio', } );
+ my $biblio3 = $builder->build( { source => 'Biblio', } );
+ my $biblio4 = $builder->build( { source => 'Biblio', } );
+
+
+ my $public_shelf = Koha::Virtualshelf->new(
+ { shelfname => "my first shelf",
+ owner => $patron1->{borrowernumber},
+ category => 2,
+ allow_add => 0,
+ allow_delete_own => 0,
+ allow_delete_other => 0,
+ }
+ )->store;
+
+ is( $public_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his public list' );
+ is( $public_shelf->can_be_viewed( $patron2->{borrowernumber} ), 1, 'Public list should be viewed by someone else' );
+
+ is( $public_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
+ is( $public_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Public list should not be deleted by someone else' );
+
+ is( $public_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
+ is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
+
+ is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
+ is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (add) by someone else' );
+
+ is( $public_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
+ is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (remove) by someone else' );
+
+
+ $public_shelf->allow_add(1);
+ $public_shelf->allow_delete_own(1);
+ $public_shelf->allow_delete_other(1);
+ $public_shelf->store;
+
+ is( $public_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his public list' );
+ is( $public_shelf->can_be_viewed( $patron2->{borrowernumber} ), 1, 'Public list should be viewed by someone else' );
+
+ is( $public_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
+ is( $public_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Public list should not be deleted by someone else' );
+
+ is( $public_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
+ is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
+
+ is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
+ is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 1, 'Public list should not be modified (add) by someone else' );
+
+ is( $public_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
+ is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 1, 'Public list should not be modified (remove) by someone else' );
+
+
+ my $private_shelf = Koha::Virtualshelf->new(
+ { shelfname => "my first shelf",
+ owner => $patron1->{borrowernumber},
+ category => 1,
+ allow_add => 0,
+ allow_delete_own => 0,
+ allow_delete_other => 0,
+ }
+ )->store;
+
+ is( $private_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his list' );
+ is( $private_shelf->can_be_viewed( $patron2->{borrowernumber} ), 0, 'Private list should not be viewed by someone else' );
+
+ is( $private_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
+ is( $private_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Private list should not be deleted by someone else' );
+
+ is( $private_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
+ is( $private_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Private list should not be managed by someone else' );
+
+ is( $private_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
+ is( $private_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Private list should not be modified (add) by someone else' );
+
+ is( $private_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
+ is( $private_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Private list should not be modified (remove) by someone else' );
+
+
+ $private_shelf->allow_add(1);
+ $private_shelf->allow_delete_own(1);
+ $private_shelf->allow_delete_other(1);
+ $private_shelf->store;
+
+ is( $private_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his list' );
+ is( $private_shelf->can_be_viewed( $patron2->{borrowernumber} ), 0, 'Private list should not be viewed by someone else' );
+
+ is( $private_shelf->can_be_deleted( $patron1->{borrowernumber} ), 1, 'The owner should be able to delete his list' );
+ is( $private_shelf->can_be_deleted( $patron2->{borrowernumber} ), 0, 'Private list should not be deleted by someone else' );
+
+ is( $private_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
+ is( $private_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Private list should not be managed by someone else' );
+
+ is( $private_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
+ is( $private_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 1, 'Private list could be modified (add) by someone else # individual check done later' );
+
+ is( $private_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
+ is( $private_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 1, 'Private list could be modified (remove) by someone else # individual check done later' );
+};
}
sub HandleShelfNumber {
- if($authorized= ShelfPossibleAction($loggedinuser, $shelfnumber, 'add')) {
+ my $shelf = Koha::Virtualshelves->find( $shelfnumber );
+ if($authorized = $shelf->can_biblios_be_added( $loggedinuser ) ) {
AddBibliosToShelf($shelfnumber, @biblionumber);
#Close this page and return
print $query->header;
}
sub HandleSelectedShelf {
- if($authorized= ShelfPossibleAction( $loggedinuser, $shelfnumber, 'add')){
+ my $shelf = Koha::Virtualshelves->find( $shelfnumber );
+ if($authorized = $shelf->can_biblios_be_added( $loggedinuser ) ) {
#confirm adding to specific shelf
- my $shelf = Koha::Virtualshelves->find( $shelfnumber );
$template->param(
singleshelf => 1,
shelfnumber => $shelf->shelfnumber,
use C4::Record;
use C4::Ris;
use C4::Csv;
+
+use Koha::Virtualshelves;
+
use utf8;
my $query = new CGI;
-my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
{
template_name => "virtualshelves/downloadshelf.tt",
query => $query,
my $shelfid = $query->param('shelfid');
my $format = $query->param('format');
my $dbh = C4::Context->dbh;
+my @messages;
if ($shelfid && $format) {
my $marcflavour = C4::Context->preference('marcflavour');
my $output='';
- # CSV
- if ($format =~ /^\d+$/) {
- my @biblios;
- foreach (@$items) {
- push @biblios, $_->{biblionumber};
- }
- $output = marc2csv(\@biblios, $format);
- }
- else { #Other formats
- foreach my $biblio (@$items) {
- my $biblionumber = $biblio->{biblionumber};
- my $record = GetMarcBiblio($biblionumber, 1);
- if ($format eq 'iso2709') {
- $output .= $record->as_usmarc();
- }
- elsif ($format eq 'ris') {
- $output .= marc2ris($record);
+ my $shelf = Koha::Virtualshelves->find($shelfid);
+ if ( $shelf ) {
+ if ( $shelf->can_be_viewed( $loggedinuser ) ) {
+
+ # CSV
+ if ($format =~ /^\d+$/) {
+ my @biblios;
+ foreach (@$items) {
+ push @biblios, $_->{biblionumber};
+ }
+ $output = marc2csv(\@biblios, $format);
}
- elsif ($format eq 'bibtex') {
- $output .= marc2bibtex($record, $biblionumber);
+ else { #Other formats
+ foreach my $biblio (@$items) {
+ my $biblionumber = $biblio->{biblionumber};
+ my $record = GetMarcBiblio($biblionumber, 1);
+ if ($format eq 'iso2709') {
+ $output .= $record->as_usmarc();
+ }
+ elsif ($format eq 'ris') {
+ $output .= marc2ris($record);
+ }
+ elsif ($format eq 'bibtex') {
+ $output .= marc2bibtex($record, $biblionumber);
+ }
+ }
}
+ print $query->header(
+ -type => 'application/octet-stream',
+ -'Content-Transfer-Encoding' => 'binary',
+ -attachment=>"shelf.$format");
+ print $output;
+ exit;
+ } else {
+ push @messages, { type => 'error', code => 'unauthorized' };
}
+ } else {
+ push @messages, { type => 'error', code => 'does_not_exist' };
}
# If it was a CSV export we change the format after the export so the file extension is fine
$format = "csv" if ($format =~ m/^\d+$/);
-
- print $query->header(
- -type => 'application/octet-stream',
- -'Content-Transfer-Encoding' => 'binary',
- -attachment=>"shelf.$format");
- print $output;
}
else {
$template->param(csv_profiles => GetCsvProfilesLoop('marc'));
$template->param(shelfid => $shelfid);
- output_html_with_http_headers $query, $cookie, $template->output;
}
+$template->param( messages => \@messages );
+output_html_with_http_headers $query, $cookie, $template->output;
#!/usr/bin/perl
-#
-# Copyright 2000-2002 Katipo Communications
+# Copyright 2015 Koha Team
#
# This file is part of Koha.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
-use strict;
-use warnings;
+use Modern::Perl;
use CGI qw ( -utf8 );
-use C4::VirtualShelves::Page;
+use C4::VirtualShelves;
use C4::Auth;
+use C4::Biblio;
+use C4::Csv;
+use C4::Koha;
+use C4::Items;
+use C4::Members;
+use C4::Output;
+use C4::XSLT;
+use Koha::Virtualshelves;
my $query = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
- {
- template_name => "virtualshelves/shelves.tt",
+ { template_name => "virtualshelves/shelves.tt",
query => $query,
type => "intranet",
authnotrequired => 0,
flagsrequired => { catalogue => 1 },
}
);
-$template->param( print => $query->param('print') );
-shelfpage('intranet', $query, $template, $loggedinuser, $cookie);
+
+my $op = $query->param('op') || 'list';
+my $referer = $query->param('referer') || $op;
+my $category = $query->param('category') || 1;
+my ( $shelf, $shelfnumber, @messages );
+
+if ( $op eq 'add_form' ) {
+ # Nothing to do
+} elsif ( $op eq 'edit_form' ) {
+ $shelfnumber = $query->param('shelfnumber');
+ $shelf = Koha::Virtualshelves->find($shelfnumber);
+
+ if ( $shelf ) {
+ $category = $shelf->category;
+ my $patron = GetMember( 'borrowernumber' => $shelf->owner );
+ $template->param( owner => $patron, );
+ unless ( $shelf->can_be_managed( $loggedinuser ) ) {
+ push @messages, { type => 'error', code => 'unauthorized_on_update' };
+ $op = 'list';
+ }
+ } else {
+ push @messages, { type => 'error', code => 'does_not_exist' };
+ }
+} elsif ( $op eq 'add' ) {
+ eval {
+ $shelf = Koha::Virtualshelf->new(
+ { shelfname => $query->param('shelfname'),
+ sortfield => $query->param('sortfield'),
+ category => $query->param('category'),
+ allow_add => $query->param('allow_add'),
+ allow_delete_own => $query->param('allow_delete_own'),
+ allow_delete_other => $query->param('allow_delete_other'),
+ owner => $query->param('owner'),
+ }
+ );
+ $shelf->store;
+ $shelfnumber = $shelf->shelfnumber;
+ };
+ if ($@) {
+ push @messages, { type => 'error', code => ref($@), msg => $@ };
+ } elsif ( not $shelf ) {
+ push @messages, { type => 'error', code => 'error_on_insert' };
+ } else {
+ push @messages, { type => 'message', code => 'success_on_insert' };
+ $op = 'view';
+ }
+} elsif ( $op eq 'edit' ) {
+ $shelfnumber = $query->param('shelfnumber');
+ $shelf = Koha::Virtualshelves->find($shelfnumber);
+
+ if ( $shelf ) {
+ $op = $referer;
+ if ( $shelf->can_be_managed( $loggedinuser ) ) {
+ $shelf->shelfname( $query->param('shelfname') );
+ $shelf->sortfield( $query->param('sortfield') );
+ $shelf->allow_add( $query->param('allow_add') );
+ $shelf->allow_delete_own( $query->param('allow_delete_own') );
+ $shelf->allow_delete_other( $query->param('allow_delete_other') );
+ $shelf->category( $query->param('category') );
+ eval { $shelf->store };
+
+ if ($@) {
+ push @messages, { type => 'error', code => 'error_on_update' };
+ $op = 'edit_form';
+ } else {
+ push @messages, { type => 'message', code => 'success_on_update' };
+ }
+ } else {
+ push @messages, { type => 'error', code => 'unauthorized_on_update' };
+ }
+ } else {
+ push @messages, { type => 'error', code => 'does_not_exist' };
+ }
+} elsif ( $op eq 'delete' ) {
+ $shelfnumber = $query->param('shelfnumber');
+ $shelf = Koha::Virtualshelves->find($shelfnumber);
+ if ($shelf) {
+ if ( $shelf->can_be_deleted( $loggedinuser ) ) {
+ eval { $shelf->delete; };
+ if ($@) {
+ push @messages, { type => 'error', code => ref($@), msg => $@ };
+ } else {
+ push @messages, { type => 'message', code => 'success_on_delete' };
+ }
+ } else {
+ push @messages, { type => 'error', code => 'unauthorized_on_delete' };
+ }
+ } else {
+ push @messages, { type => 'error', code => 'does_not_exist' };
+ }
+ $op = 'list';
+} elsif ( $op eq 'add_biblio' ) {
+ $shelfnumber = $query->param('shelfnumber');
+ $shelf = Koha::Virtualshelves->find($shelfnumber);
+ if ($shelf) {
+ if( my $barcode = $query->param('barcode') ) {
+ my $item = GetItem( 0, $barcode);
+ if (defined $item && $item->{itemnumber}) {
+ my $biblio = GetBiblioFromItemNumber( $item->{itemnumber} );
+ if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
+ my $added = eval { $shelf->add_biblio( $biblio->{biblionumber}, $loggedinuser ); };
+ if ($@) {
+ push @messages, { type => 'error', code => ref($@), msg => $@ };
+ } elsif ( $added ) {
+ push @messages, { type => 'message', code => 'success_on_add_biblio' };
+ } else {
+ push @messages, { type => 'message', code => 'error_on_add_biblio' };
+ }
+ } else {
+ push @messages, { type => 'error', code => 'unauthorized_on_add_biblio' };
+ }
+ } else {
+ push @messages, { type => 'error', code => 'item_does_not_exist' };
+ }
+ }
+ } else {
+ push @messages, { type => 'error', code => 'does_not_exist' };
+ }
+ $op = $referer;
+} elsif ( $op eq 'remove_biblios' ) {
+ $shelfnumber = $query->param('shelfnumber');
+ $shelf = Koha::Virtualshelves->find($shelfnumber);
+ my @biblionumbers = $query->param('biblionumber');
+ if ($shelf) {
+ if ( $shelf->can_biblios_be_removed( $loggedinuser ) ) {
+ my $number_of_biblios_removed = eval {
+ $shelf->remove_biblios(
+ {
+ biblionumbers => \@biblionumbers,
+ borrowernumber => $loggedinuser,
+ }
+ );
+ };
+ if ($@) {
+ push @messages, { type => 'error', code => ref($@), msg => $@ };
+ } elsif ( $number_of_biblios_removed ) {
+ push @messages, { type => 'message', code => 'success_on_remove_biblios' };
+ } else {
+ push @messages, { type => 'error', code => 'no_biblio_removed' };
+ }
+ } else {
+ push @messages, { type => 'error', code => 'unauthorized_on_remove_biblios' };
+ }
+ } else {
+ push @messages, { type => 'error', code => 'does_not_exist' };
+ }
+ $op = $referer;
+}
+
+if ( $op eq 'view' ) {
+ $shelfnumber ||= $query->param('shelfnumber');
+ $shelf = Koha::Virtualshelves->find($shelfnumber);
+ if ( $shelf ) {
+ if ( $shelf->can_be_viewed( $loggedinuser ) ) {
+ my $sortfield = $query->param('sortfield') || $shelf->sortfield; # Passed in sorting overrides default sorting
+ my $direction = $query->param('direction') || 'asc';
+ my ( $shelflimit, $shelfoffset, $itemoff );
+ unless ( $query->param('print') ) {
+ $shelflimit = C4::Context->preference('numSearchResults') || 20;
+ $itemoff = ( $query->param('itemoff') ? $query->param('itemoff') : 1 );
+ $shelfoffset = ( $itemoff - 1 ) * $shelflimit; # Sets the offset to begin retrieving items at
+ }
+ my ( $items, $totitems ) = GetShelfContents( $shelfnumber, $shelflimit, $shelfoffset, $sortfield, $direction );
+
+ my $borrower = GetMember( borrowernumber => $loggedinuser );
+
+ for my $this_item (@$items) {
+ my $biblionumber = $this_item->{biblionumber};
+ my $record = GetMarcBiblio($biblionumber);
+
+ if ( C4::Context->preference("XSLTResultsDisplay") ) {
+ $this_item->{XSLTBloc} = XSLTParse4Display( $biblionumber, $record, "XSLTResultsDisplay" );
+ }
+
+ my $marcflavour = C4::Context->preference("marcflavour");
+ $this_item->{'imageurl'} = getitemtypeinfo( $this_item->{'itemtype'}, 'intranet' )->{'imageurl'};
+ $this_item->{'coins'} = GetCOinSBiblio($record);
+ $this_item->{'subtitle'} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $this_item->{'biblionumber'} ) );
+ $this_item->{'normalized_upc'} = GetNormalizedUPC( $record, $marcflavour );
+ $this_item->{'normalized_ean'} = GetNormalizedEAN( $record, $marcflavour );
+ $this_item->{'normalized_oclc'} = GetNormalizedOCLCNumber( $record, $marcflavour );
+ $this_item->{'normalized_isbn'} = GetNormalizedISBN( undef, $record, $marcflavour );
+
+ unless ( defined $this_item->{size} ) {
+
+ #TT has problems with size
+ $this_item->{size} = q||;
+ }
+
+ # Getting items infos for location display
+ my @items_infos = &GetItemsLocationInfo( $this_item->{'biblionumber'} );
+ $this_item->{'ITEM_RESULTS'} = \@items_infos;
+ }
+
+ # Build drop-down list for 'Add To:' menu...
+ my ( $totalref, $pubshelves, $barshelves ) = C4::VirtualShelves::GetSomeShelfNames( $loggedinuser, 'COMBO', 1 );
+ $template->param(
+ addbarshelves => $totalref->{bartotal},
+ addbarshelvesloop => $barshelves,
+ addpubshelves => $totalref->{pubtotal},
+ addpubshelvesloop => $pubshelves,
+ can_manage_shelf => $shelf->can_be_managed($loggedinuser),
+ can_remove_shelf => $shelf->can_be_deleted($loggedinuser),
+ can_remove_biblios => $shelf->can_biblios_be_removed($loggedinuser),
+ can_add_biblios => $shelf->can_biblios_be_added($loggedinuser),
+ sortfield => $sortfield,
+ itemsloop => $items,
+ sortfield => $sortfield,
+ direction => $direction,
+ );
+ if ($shelflimit) {
+ $template->param(
+ pagination_bar => pagination_bar(
+ q||, ( int( $totitems / $shelflimit ) ) + ( ( $totitems % $shelflimit ) > 0 ? 1 : 0 ),
+ $itemoff, "itemoff", { op => 'view', shelfnumber => $shelf->shelfnumber, sortfield => $sortfield, direction => $direction, }
+ ),
+ );
+ }
+ } else {
+ push @messages, { type => 'error', code => 'unauthorized_on_view' };
+ }
+ } else {
+ push @messages, { type => 'error', code => 'does_not_exist' };
+ }
+}
+
+$template->param(
+ op => $op,
+ referer => $referer,
+ shelf => $shelf,
+ messages => \@messages,
+ category => $category,
+ print => $query->param('print') || 0,
+ csv_profiles => GetCsvProfilesLoop('marc'),
+);
+
+output_html_with_http_headers $query, $cookie, $template->output;