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";
56 $template->param( { loggedinuser => $loggedinuser } );
58 # getting the Shelves list
59 my $shelflist = GetShelves( $loggedinuser, 2 );
60 my $op = $query->param('op');
62 # the format of this is unindented for ease of diff comparison to the old script
63 # Note: do not mistake the assignment statements below for comparisons!
65 if ( $query->param('modifyshelfcontents') ) {
66 my ($shelfnumber,$barcode,$item,$biblio);
67 if ($shelfnumber = $query->param('viewshelf')) {
68 if (ShelfPossibleAction($loggedinuser, $shelfnumber, 'manage')) {
69 if ($barcode = $query->param('addbarcode')) {
70 if ($item = GetItem( 0, $barcode )) {
71 $biblio = GetBiblioFromItemNumber($item->{'itemnumber'});
72 AddToShelf($biblio->{'biblionumber'}, $shelfnumber) or
73 push @paramsloop, {duplicatebiblio=>$barcode};
74 } else { push @paramsloop, {failgetitem=>$barcode}; }
76 (grep {/REM-(\d+)/} $query->param) or push @paramsloop, {nobarcode=>1};
77 foreach ($query->param) {
80 "SHELVES: user $loggedinuser removing item $1 from shelf $shelfnumber";
81 DelFromShelf($1, $shelfnumber); # $1 is biblionumber
84 } else { push @paramsloop, {nopermission=>$shelfnumber}; }
85 } else { push @paramsloop, {noshelfnumber=>1}; }
89 # set the default tab, etc. (for OPAC)
90 my $shelf_type = $query->param('display');
91 if (defined $shelf_type) {
92 if ($shelf_type eq 'privateshelves') {
93 $template->param(showprivateshelves => 1);
94 } elsif ($shelf_type eq 'publicshelves') {
95 $template->param(showpublicshelves => 1);
98 $debug and warn "Invalid 'display' param ($shelf_type)";
101 $template->param(showprivateshelves => 1);
107 if ( $op eq 'modifsave' ) {
109 $query->param('shelfnumber'), $query->param('shelfname'),
110 $loggedinuser, $query->param('category'), $query->param('sortfield')
112 $shelflist = GetShelves( $loggedinuser, 2 ); # refresh after mods
113 } elsif ( $op eq 'modif' ) {
114 my ( $shelfnumber, $shelfname, $owner, $category, $sortfield ) =GetShelf( $query->param('shelf') );
117 shelfnumber => $shelfnumber,
118 shelfname => $shelfname,
119 "category$category" => 1,
120 "sort_$sortfield" => 1,
125 if (my $shelfnumber = $query->param('viewshelf') ) {
126 #check that the user can view the shelf
127 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
128 my $items = GetShelfContents($shelfnumber);
131 foreach (grep {$i++ % 2} @$items) { # every other item
134 # my $manageshelf = &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' );
135 # ($manageshelf) and $showadd = 1;
137 shelfname => $shelflist->{$shelfnumber}->{'shelfname'},
138 shelfnumber => $shelfnumber,
139 viewshelf => $shelfnumber,
140 manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ),
143 } else { push @paramsloop, {nopermission=>$shelfnumber}; }
146 if ( $query->param('shelves') ) {
147 if ( my $newshelf = $query->param('addshelf') ) {
148 my $shelfnumber = AddShelf(
150 $query->param('owner'),
151 $query->param('category')
154 if ( $shelfnumber == -1 ) { #shelf already exists.
156 push @paramsloop, { already => $newshelf };
157 $template->param(shelfnumber => $shelfnumber);
159 print $query->redirect($pages{$type}->{redirect} . "?viewshelf=$shelfnumber");
164 foreach ( $query->param() ) {
168 if (defined $shelflist->{$number}) {
169 my $name = $shelflist->{$number}->{'shelfname'};
170 if (DelShelf($number)) {
171 delete $shelflist->{$number};
172 $line{delete_ok} = $name;
175 $line{delete_fail} = $name;
178 $line{unrecognized} = $number;
180 push(@paramsloop, \%line);
181 # print $query->redirect($pages{$type}->{redirect});
185 $stay and $template->param(shelves => 1);
190 (@paramsloop) and $template->param(paramsloop => \@paramsloop);
191 # rebuild shelflist in case a shelf has been added
192 # $shelflist = GetShelves( $loggedinuser, 2 );
193 $showadd and $template->param(showadd => 1);
197 my $numberCanManage = 0;
199 foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflist->{$b}->{'shelfname'}) } keys %$shelflist) {
201 (++$i % 2) and $line{'toggle'} = $i;
202 $line{'shelf'} = $element;
203 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
204 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
205 $line{'sortfield'} = $shelflist->{$element}->{'sortfield'};
206 $line{"viewcategory$shelflist->{$element}->{'category'}"} = 1;
207 $line{'canmanage'} = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
208 if ($shelflist->{$element}->{'owner'} eq $loggedinuser) {
211 $line{'firstname'} = $shelflist->{$element}->{'firstname'};
212 $line{'surname'} = $shelflist->{$element}->{'surname'} ;
214 $numberCanManage++ if $line{'canmanage'};
215 if ($shelflist->{$element}->{'category'} eq '1') {
216 push (@shelveslooppriv, \%line);
218 push (@shelvesloop, \%line);
223 shelveslooppriv => \@shelveslooppriv,
224 shelvesloop => \@shelvesloop,
225 shelvesloopall => [(@shelvesloop, @shelveslooppriv)],
226 numberCanManage => $numberCanManage,
227 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
229 if ($template->param('viewshelf') or
230 $template->param( 'shelves' ) or
231 $template->param( 'edit' ) ) {
232 $template->param(vseflag => 1);
234 if ($template->param( 'shelves' ) or
235 $template->param( 'edit' ) ) {
236 $template->param( seflag => 1);
239 output_html_with_http_headers $query, $cookie, $template->output;
247 VirtualShelves/Page.pm
251 Module used for both OPAC and intranet pages.
253 =head1 CGI PARAMETERS
257 =item C<modifyshelfcontents>
259 If this script has to modify the shelf content.
263 To know on which shelf to work.
270 * modif: show the template allowing modification of the shelves;
271 * modifsave: save changes from modif mode.
275 Load template with 'viewshelves param' displaying the shelf's information.
279 If the param shelves == 1, then add or delete a shelf.
283 If the param shelves == 1, then addshelf is the name of the shelf to add.