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 shelve content.
39 to know on which shelve this script has to work.
46 * modifsave to save change on the shelves
47 * modif to change the template to allow to modify the shelves.
51 to load the template with 'viewshelves param' which allow to read the shelves information.
55 if equals to 1. then call the function shelves which add
60 if the param shelves = 1 then addshelf must be equals to the name of the shelf to add.
70 use C4::VirtualShelves;
78 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
80 template_name => "opac-shelves.tmpl",
87 if ( $query->param('modifyshelfcontents') ) {
88 my $shelfnumber = $query->param('viewshelf');
89 my $barcode = $query->param('addbarcode');
90 my ($item) = GetItemnumberFromBarcode($barcode);
91 my ($biblio) = GetBiblioFromItemNumber($item->{'itemnumber'});
92 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) {
93 AddToShelf( $biblio->{'biblionumber'}, $shelfnumber );
94 foreach ( $query->param ) {
96 my $biblionumber = $1;
97 DelFromShelf( $biblionumber, $shelfnumber );
103 # set the default tab, etc.
104 my $shelf_type = $query->param('display');
105 if ((!$shelf_type) || ($shelf_type eq 'privateshelves')) {
106 $template->param(showprivateshelves => 1);
107 } elsif ($shelf_type eq 'publicshelves') {
108 $template->param(showpublicshelves => 1);
111 # getting the Shelves list
112 my $shelflist = GetShelves( $loggedinuser, 2 );
113 $template->param( { loggedinuser => $loggedinuser } );
114 my $op = $query->param('op');
117 if ( $op && ( $op eq 'modifsave' ) ) {
119 $query->param('shelfnumber'), $query->param('shelfname'),
120 $loggedinuser, $query->param('category'), $query->param('sortfield')
124 if ( $op && ( $op eq 'modif' ) ) {
125 my ( $shelfnumber, $shelfname, $owner, $category, $sortfield ) =
126 GetShelf( $query->param('shelf') );
129 shelfnumber => $shelfnumber,
130 shelfname => $shelfname,
131 "category$category" => 1,
132 "sort_$sortfield" => 1,
136 if ( $query->param('viewshelf') ) {
138 #check that the user can view the shelf
139 my $shelfnumber = $query->param('viewshelf');
140 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
141 my $items = GetShelfContents($shelfnumber);
143 shelfname => $shelflist->{$shelfnumber}->{'shelfname'},
144 shelfnumber => $shelfnumber,
145 viewshelf => $query->param('viewshelf'),
146 manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ),
152 if ( $query->param('shelves') ) {
153 if ( my $newshelf = $query->param('addshelf') ) {
154 my $shelfnumber = AddShelf(
156 $query->param('owner'),
157 $query->param('category')
160 if ( $shelfnumber == -1 ) { #shelf already exists.
163 shelfnumber => $shelfnumber,
168 print $query->redirect("/cgi-bin/koha/opac-shelves.pl?viewshelf=$shelfnumber");
172 foreach ( $query->param() ) {
176 my ( $status, $count ) = DelShelf($delshelf);
178 $line{'status'} = $status;
179 $line{'count'} = $count;
181 print $query->redirect("/cgi-bin/koha/opac-shelves.pl");
185 #if the shelf is not deleted, %line points on null
186 # push( @paramsloop, \%line );
188 $template->param( paramsloop => \@paramsloop );
189 my ($shelflist) = GetShelves( $loggedinuser, 2 );
192 foreach my $element ( sort keys %$shelflist ) {
194 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
195 $line{'toggle'} = $color;
196 $line{'shelf'} = $element;
197 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
198 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
199 push( @shelvesloop, \%line );
202 shelvesloop => \@shelvesloop,
209 # rebuild shelflist in case a shelf has been added
210 ($shelflist) = GetShelves( $loggedinuser, 2 ) ;
215 foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflist->{$b}->{'shelfname'}) } keys %$shelflist) {
218 ($color eq 0) ? ($color=1) : ($color=0);
219 if ($shelflist->{$element}->{'category'} eq 2) {
220 $line{'toggle'}= $color;
221 $line{'shelf'}=$element;
222 $line{'shelfname'}=$shelflist->{$element}->{'shelfname'};
223 $line{'sortfield'}=$shelflist->{$element}->{'sortfield'};
224 $line{"category".$shelflist->{$element}->{'category'}} = 1;
225 $line{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser;
226 $line{'shelfvirtualcount'}=$shelflist->{$element}->{'count'};
227 $line{'canmanage'} = ShelfPossibleAction($loggedinuser,$element,'manage');
228 $line{'firstname'}=$shelflist->{$element}->{'firstname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
229 $line{'surname'}=$shelflist->{$element}->{'surname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
230 push (@shelvesloop, \%line);
231 } elsif ($shelflist->{$element}->{'category'} eq 1) {
232 $linepriv{'toggle'}= $color;
233 $linepriv{'shelf'}=$element;
234 $linepriv{'shelfname'}=$shelflist->{$element}->{'shelfname'};
235 $linepriv{'sortfield'}=$shelflist->{$element}->{'sortfield'};
236 $linepriv{"category".$shelflist->{$element}->{'category'}} = 1;
237 $linepriv{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser;
238 $linepriv{'shelfvirtualcount'}=$shelflist->{$element}->{'count'};
239 $linepriv{'canmanage'} = ShelfPossibleAction($loggedinuser,$element,'manage');
240 $linepriv{'firstname'}=$shelflist->{$element}->{'firstname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
241 $linepriv{'surname'}=$shelflist->{$element}->{'surname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
242 push (@shelveslooppriv, \%linepriv);
247 shelveslooppriv => \@shelveslooppriv,
248 shelvesloop => \@shelvesloop,
249 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
252 output_html_with_http_headers $query, $cookie, $template->output;