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);
104 my($okmanage, $okview);
105 my $shelfnumber = $query->param('shelfnumber') || $query->param('viewshelf');
107 $okmanage = &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' );
108 $okview = &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' );
114 push @paramsloop, {nopermission=>$shelfnumber};
117 if ( $op eq 'modifsave' ) {
119 $shelfnumber, $query->param('shelfname'), $loggedinuser,
120 $query->param('category'), $query->param('sortfield')
122 $shelflist = GetShelves( $loggedinuser, 2 ); # refresh after mods
123 } elsif ( $op eq 'modif' ) {
124 my ( $shelfnumber2, $shelfname, $owner, $category, $sortfield ) =GetShelf( $query->param('shelf') );
127 shelfnumber => $shelfnumber2,
128 shelfname => $shelfname,
130 "category$category" => 1,
131 "sort_$sortfield" => 1,
136 if ($shelfnumber = $query->param('viewshelf') ) {
137 #check that the user can view the shelf
138 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
139 my $items = GetShelfContents($shelfnumber);
142 foreach (grep {$i++ % 2} @$items) { # every other item
145 # my $manageshelf = &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' );
146 # ($manageshelf) and $showadd = 1;
148 shelfname => $shelflist->{$shelfnumber}->{'shelfname'},
149 shelfnumber => $shelfnumber,
150 viewshelf => $shelfnumber,
151 manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ),
154 } else { push @paramsloop, {nopermission=>$shelfnumber}; }
157 if ( $query->param('shelves') ) {
159 if (my $newshelf = $query->param('addshelf')) {
160 # note: a user can always add a new shelf
161 my $shelfnumber = AddShelf(
163 $query->param('owner'),
164 $query->param('category')
167 if ( $shelfnumber == -1 ) { #shelf already exists.
169 push @paramsloop, { already => $newshelf };
170 $template->param(shelfnumber => $shelfnumber);
172 print $query->redirect($pages{$type}->{redirect} . "?viewshelf=$shelfnumber");
176 foreach ($query->param()) {
179 unless (defined $shelflist->{$number}) {
180 push(@paramsloop, {unrecognized=>$number}); last;
182 unless (ShelfPossibleAction($loggedinuser, $number, 'manage')) {
183 push(@paramsloop, {nopermission=>$shelfnumber}); last;
185 my $contents = GetShelfContents($number);
186 if (my $count = scalar @$contents){
187 unless (scalar grep {/^CONFIRM-$number$/} $query->param()) {
188 push(@paramsloop, {need_confirm=>$shelflist->{$number}->{shelfname}, count=>$count});
189 $shelflist->{$number}->{confirm} = $number;
193 my $name = $shelflist->{$number}->{'shelfname'};
194 unless (DelShelf($number)) {
195 push(@paramsloop, {delete_fail=>$name}); last;
197 delete $shelflist->{$number};
198 push(@paramsloop, {delete_ok=>$name});
199 # print $query->redirect($pages{$type}->{redirect}); exit;
202 $stay and $template->param(shelves => 1);
207 (@paramsloop) and $template->param(paramsloop => \@paramsloop);
208 # rebuild shelflist in case a shelf has been added
209 # $shelflist = GetShelves( $loggedinuser, 2 );
210 $showadd and $template->param(showadd => 1);
214 my $numberCanManage = 0;
216 foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflist->{$b}->{'shelfname'}) } keys %$shelflist) {
218 (++$i % 2) and $shelflist->{$element}->{toggle} = 1; # $line{'toggle'} = $i;
219 $shelflist->{$element}->{shelf} = $element;
220 my $category = $shelflist->{$element}->{'category'};
221 my $canmanage = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
222 $shelflist->{$element}->{"viewcategory$category"} = 1;
223 $shelflist->{$element}->{canmanage} = $canmanage;
224 if ($shelflist->{$element}->{'owner'} eq $loggedinuser) {
225 $shelflist->{$element}->{'mine'} = 1;
227 $numberCanManage++ if $canmanage;
228 if ($shelflist->{$element}->{'category'} eq '1') {
229 push (@shelveslooppriv, $shelflist->{$element});
231 push (@shelvesloop, $shelflist->{$element});
236 shelveslooppriv => \@shelveslooppriv,
237 shelvesloop => \@shelvesloop,
238 shelvesloopall => [(@shelvesloop, @shelveslooppriv)],
239 numberCanManage => $numberCanManage,
240 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
242 if ($template->param('viewshelf') or
243 $template->param( 'shelves' ) or
244 $template->param( 'edit' ) ) {
245 $template->param(vseflag => 1);
247 if ($template->param( 'shelves' ) or
248 $template->param( 'edit' ) ) {
249 $template->param( seflag => 1);
252 output_html_with_http_headers $query, $cookie, $template->output;
260 VirtualShelves/Page.pm
264 Module used for both OPAC and intranet pages.
266 =head1 CGI PARAMETERS
270 =item C<modifyshelfcontents>
272 If this script has to modify the shelf content.
276 To know on which shelf to work.
283 * modif: show the template allowing modification of the shelves;
284 * modifsave: save changes from modif mode.
288 Load template with 'viewshelves param' displaying the shelf's information.
292 If the param shelves == 1, then add or delete a shelf.
296 If the param shelves == 1, then addshelf is the name of the shelf to add.