1 package C4::VirtualShelves::Page;
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
21 # perldoc at the end of the file, per convention.
26 use C4::VirtualShelves;
33 use vars qw($debug @EXPORT @ISA $VERSION);
38 @EXPORT = qw(&shelfpage);
39 $debug = $ENV{DEBUG} || 0;
44 redirect=>'/cgi-bin/koha/virtualshelves/shelves.pl',
47 redirect=>'/cgi-bin/koha/opac-shelves.pl',
51 sub shelfpage ($$$$$) {
52 my ($type, $query, $template, $loggedinuser, $cookie ) = @_;
53 ($pages{$type}) or $type = 'opac';
54 $query or die "No query";
55 $template or die "No template";
57 # the format of this is unindented for ease of diff comparison to the old script
59 if ( $query->param('modifyshelfcontents') ) {
60 my $shelfnumber = $query->param('viewshelf');
61 my $barcode = $query->param('addbarcode');
62 my ($item) = GetItem( 0, $barcode );
63 my ($biblio) = GetBiblioFromItemNumber($item->{'itemnumber'});
64 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) {
65 AddToShelf( $biblio->{'biblionumber'}, $shelfnumber );
66 foreach ( $query->param ) {
68 $debug and warn "SHELVES: user $loggedinuser removing item $1 from shelf $shelfnumber";
69 DelFromShelf( $1, $shelfnumber ); # $1 is biblionumber
75 # set the default tab, etc. (for OPAC)
76 my $shelf_type = $query->param('display');
77 if (defined $shelf_type) {
78 if ($shelf_type eq 'privateshelves') {
79 $template->param(showprivateshelves => 1);
80 } elsif ($shelf_type eq 'publicshelves') {
81 $template->param(showpublicshelves => 1);
84 $debug and warn "Invalid 'display' param ($shelf_type)";
87 $template->param(showprivateshelves => 1);
90 # getting the Shelves list
91 my $shelflist = GetShelves( $loggedinuser, 2 );
92 $template->param( { loggedinuser => $loggedinuser } );
93 my $op = $query->param('op');
97 if ( $op eq 'modifsave' ) {
99 $query->param('shelfnumber'), $query->param('shelfname'),
100 $loggedinuser, $query->param('category'), $query->param('sortfield')
102 $shelflist = GetShelves( $loggedinuser, 2 ); # refresh after mods
103 } elsif ( $op eq 'modif' ) {
104 my ( $shelfnumber, $shelfname, $owner, $category, $sortfield ) =GetShelf( $query->param('shelf') );
107 shelfnumber => $shelfnumber,
108 shelfname => $shelfname,
109 "category$category" => 1,
110 "sort_$sortfield" => 1,
115 if ( $query->param('viewshelf') ) {
116 #check that the user can view the shelf
117 my $shelfnumber = $query->param('viewshelf');
118 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
119 my $items = GetShelfContents($shelfnumber);
122 foreach (grep {$i++ % 2} @$items) { # every other item
125 # my $manageshelf = &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' );
126 # ($manageshelf) and $showadd = 1;
128 shelfname => $shelflist->{$shelfnumber}->{'shelfname'},
129 shelfnumber => $shelfnumber,
130 viewshelf => $query->param('viewshelf'),
131 manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ),
137 if ( $query->param('shelves') ) {
138 if ( my $newshelf = $query->param('addshelf') ) {
139 my $shelfnumber = AddShelf(
141 $query->param('owner'),
142 $query->param('category')
145 if ( $shelfnumber == -1 ) { #shelf already exists.
148 shelfnumber => $shelfnumber,
152 print $query->redirect($pages{$type}->{redirect} . "?viewshelf=$shelfnumber");
157 foreach ( $query->param() ) {
161 if (defined $shelflist->{$number}) {
162 my $name = $shelflist->{$number}->{'shelfname'};
163 if (DelShelf($number)) {
164 delete $shelflist->{$number};
165 $line{delete_ok} = $name;
167 $line{delete_fail} = $name;
170 $line{unrecognized} = $number;
172 push(@paramsloop, \%line);
173 # print $query->redirect("/cgi-bin/koha/virtualshelves/shelves.pl"); exit;
177 paramsloop => \@paramsloop,
184 # rebuild shelflist in case a shelf has been added
185 $shelflist = GetShelves( $loggedinuser, 2 );
186 $showadd and $template->param(showadd => 1);
190 my $numberCanManage = 0;
192 foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflist->{$b}->{'shelfname'}) } keys %$shelflist) {
194 (++$i % 2) and $line{'toggle'} = $i;
195 $line{'shelf'} = $element;
196 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
197 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
198 $line{'sortfield'} = $shelflist->{$element}->{'sortfield'};
199 $line{"viewcategory$shelflist->{$element}->{'category'}"} = 1;
200 $line{'canmanage'} = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
201 if ($shelflist->{$element}->{'owner'} eq $loggedinuser) {
204 $line{'firstname'} = $shelflist->{$element}->{'firstname'};
205 $line{'surname'} = $shelflist->{$element}->{'surname'} ;
207 $numberCanManage++ if $line{'canmanage'};
208 if ($shelflist->{$element}->{'category'} eq '1') {
209 push (@shelveslooppriv, \%line);
211 push (@shelvesloop, \%line);
216 shelveslooppriv => \@shelveslooppriv,
217 shelvesloop => \@shelvesloop,
218 shelvesloopall => [(@shelvesloop, @shelveslooppriv)],
219 numberCanManage => $numberCanManage,
220 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
222 if ($template->param('viewshelf') or
223 $template->param( 'shelves' ) or
224 $template->param( 'edit' ) ) {
225 $template->param(vseflag => 1);
227 if ($template->param( 'shelves' ) or
228 $template->param( 'edit' ) ) {
229 $template->param( seflag => 1);
232 output_html_with_http_headers $query, $cookie, $template->output;
240 VirtualShelves/Page.pm
244 Module used for both OPAC and intranet pages.
246 =head1 CGI PARAMETERS
250 =item C<modifyshelfcontents>
252 If this script has to modify the shelf content.
256 To know on which shelf to work.
263 * modifsave to save change on the shelves
264 * modif to change the template to allow to modify the shelves.
268 To load the template with 'viewshelves param' which allow to read the shelves information.
272 If equals to 1. then call the function shelves which add
277 If the param shelves = 1 then addshelf must be equals to the name of the shelf to add.