3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
27 this script is used to script to provide virtualshelf management
33 =item C<modifyshelfcontents>
35 if this script has to modify the shelf content.
39 to know on which shelf this script has to work.
45 op can equal the following values:
46 * 'modifsave' to save changes on the shelves
47 * 'modif' to change the template to allow modification of the shelves.
51 to load the template with 'viewshelves param' which allows reading the shelves information.
55 if == 1, then call the function shelves to add or delete a shelf.
59 if the param shelves == 1, then addshelf must be equals to the name of the shelf to add.
69 use C4::VirtualShelves;
78 $debug = $ENV{DEBUG} || 0;
83 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
85 template_name => "opac-shelves.tmpl",
92 if ( $query->param('modifyshelfcontents') ) {
93 my $shelfnumber = $query->param('viewshelf');
94 my $barcode = $query->param('addbarcode');
95 my ($item) = GetItemnumberFromBarcode($barcode);
96 my ($biblio) = GetBiblioFromItemNumber($item->{'itemnumber'});
97 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) {
98 AddToShelf( $biblio->{'biblionumber'}, $shelfnumber );
99 foreach ( $query->param ) {
101 $debug and warn "SHELVES: user $loggedinuser removing item $1 from shelf $shelfnumber";
102 DelFromShelf( $1, $shelfnumber ); # $1 is biblionumber
108 # set the default tab, etc.
109 my $shelf_type = $query->param('display');
110 if (defined $shelf_type) {
111 if ($shelf_type eq 'privateshelves') {
112 $template->param(showprivateshelves => 1);
113 } elsif ($shelf_type eq 'publicshelves') {
114 $template->param(showpublicshelves => 1);
117 $debug and warn "Invalid 'display' param ($shelf_type)";
120 $template->param(showprivateshelves => 1);
123 # getting the Shelves list
124 my $shelflist = GetShelves( $loggedinuser, 2 );
125 $template->param( { loggedinuser => $loggedinuser } );
126 my $op = $query->param('op');
130 if ( $op eq 'modifsave' ) {
132 $query->param('shelfnumber'), $query->param('shelfname'),
133 $loggedinuser, $query->param('category'), $query->param('sortfield')
135 $shelflist = GetShelves( $loggedinuser, 2 ); # refresh after mods
136 } elsif ( $op eq 'modif' ) {
137 my ( $shelfnumber, $shelfname, $owner, $category, $sortfield ) =GetShelf( $query->param('shelf') );
140 shelfnumber => $shelfnumber,
141 shelfname => $shelfname,
142 "category$category" => 1,
143 "sort_$sortfield" => 1,
148 if ( $query->param('viewshelf') ) {
149 #check that the user can view the shelf
150 my $shelfnumber = $query->param('viewshelf');
151 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
152 my $items = GetShelfContents($shelfnumber);
155 foreach (grep {$i++ % 2} @$items) { # every other item
159 shelfname => $shelflist->{$shelfnumber}->{'shelfname'},
160 shelfnumber => $shelfnumber,
161 viewshelf => $query->param('viewshelf'),
162 manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ),
165 } # else {;} # FIXME - some kind of warning *may* be in order
168 if ( $query->param('shelves') ) {
169 if ( my $newshelf = $query->param('addshelf') ) {
170 my $shelfnumber = AddShelf(
172 $query->param('owner'),
173 $query->param('category')
176 if ( $shelfnumber == -1 ) { #shelf already exists.
179 shelfnumber => $shelfnumber,
180 already => $newshelf,
183 print $query->redirect("/cgi-bin/koha/opac-shelves.pl?viewshelf=$shelfnumber");
184 exit; # can't redirect AND expect %line to DO anything!
188 foreach ( $query->param() ) {
189 /^DEL-(\d+)/ or next;
191 ( $line{status}, $line{count} ) = DelShelf($1);
192 (defined $shelflist->{$1}) and delete $shelflist->{$1};
193 # print $query->redirect("/cgi-bin/koha/opac-shelves.pl"); exit;
194 # can't redirect and expect %line to DO anything!
195 push( @paramsloop, \%line );
199 paramsloop => \@paramsloop,
206 # rebuilding shelflist (in case a shelf has been added) is not necessary since add redirects!
208 $showadd and $template->param(showadd => 1);
213 foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflist->{$b}->{'shelfname'}) } keys %$shelflist) {
215 $color = ($color) ? 0 : 1;
216 $color and $line{'toggle'} = $color;
217 $line{'shelf'} = $element;
218 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
219 $line{'sortfield'} = $shelflist->{$element}->{'sortfield'};
220 $line{"category".$shelflist->{$element}->{'category'}} = 1;
221 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
222 $line{'canmanage'} = ShelfPossibleAction($loggedinuser,$element,'manage');
223 if ($shelflist->{$element}->{'owner'} eq $loggedinuser) {
226 $line{'firstname'} = $shelflist->{$element}->{'firstname'};
227 $line{ 'surname' } = $shelflist->{$element}->{ 'surname' };
229 if ($shelflist->{$element}->{'category'} eq 2) {
230 push (@shelvesloop, \%line);
231 } elsif ($shelflist->{$element}->{'category'} eq 1) {
232 push (@shelveslooppriv, \%line);
237 shelveslooppriv => \@shelveslooppriv,
238 shelvesloop => \@shelvesloop,
239 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
242 output_html_with_http_headers $query, $cookie, $template->output;