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
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.
68 use C4::VirtualShelves;
75 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
77 template_name => "virtualshelves/shelves.tmpl",
81 flagsrequired => { catalogue => 1 },
85 if ( $query->param('modifyshelfcontents') ) {
86 my $shelfnumber = $query->param('viewshelf');
87 my $barcode = $query->param('addbarcode');
88 my ($item) = GetItem( 0, $barcode );
89 my ($biblio) = GetBiblioFromItemNumber($item->{'itemnumber'});
90 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) {
91 AddToShelf( $biblio->{'biblionumber'}, $shelfnumber );
92 foreach ( $query->param ) {
94 my $biblionumber = $1;
95 DelFromShelf( $biblionumber, $shelfnumber );
101 # getting the Shelves list
102 my $shelflist = GetShelves( $loggedinuser, 2 );
103 $template->param( { loggedinuser => $loggedinuser } );
104 my $op = $query->param('op');
107 if ( $op && ( $op eq 'modifsave' ) ) {
109 $query->param('shelfnumber'), $query->param('shelfname'),
110 $loggedinuser, $query->param('category'), $query->param('sortfield')
114 if ( $op && ( $op eq 'modif' ) ) {
115 my ( $shelfnumber, $shelfname, $owner, $category, $sortfield ) =
116 GetShelf( $query->param('shelf') );
119 shelfnumber => $shelfnumber,
120 shelfname => $shelfname,
121 "category$category" => 1,
122 "sort_$sortfield" => 1,
126 if ( $query->param('viewshelf') ) {
128 #check that the user can view the shelf
129 my $shelfnumber = $query->param('viewshelf');
130 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
131 my $items = GetShelfContents($shelfnumber);
133 shelfname => $shelflist->{$shelfnumber}->{'shelfname'},
134 shelfnumber => $shelfnumber,
135 viewshelf => $query->param('viewshelf'),
136 manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ),
142 if ( $query->param('shelves') ) {
143 if ( my $newshelf = $query->param('addshelf') ) {
144 my $shelfnumber = AddShelf(
146 $query->param('owner'),
147 $query->param('category')
150 if ( $shelfnumber == -1 ) { #shelf already exists.
153 shelfnumber => $shelfnumber,
158 print $query->redirect("/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=$shelfnumber");
162 foreach ( $query->param() ) {
166 my ( $status, $count ) = DelShelf($delshelf);
168 $line{'status'} = $status;
169 $line{'count'} = $count;
171 print $query->redirect("/cgi-bin/koha/virtualshelves/shelves.pl");
175 #if the shelf is not deleted, %line points on null
176 # push( @paramsloop, \%line );
178 $template->param( paramsloop => \@paramsloop );
179 my ($shelflist) = GetShelves( $loggedinuser, 2 );
182 foreach my $element ( sort keys %$shelflist ) {
184 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
185 $line{'toggle'} = $color;
186 $line{'shelf'} = $element;
187 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
188 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
189 push( @shelvesloop, \%line );
192 shelvesloop => \@shelvesloop,
199 # rebuild shelflist in case a shelf has been added
200 $shelflist = GetShelves( $loggedinuser, 2 );
203 my $numberCanManage = 0;
205 foreach my $element ( sort keys %$shelflist ) {
207 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
208 $line{'toggle'} = $color;
209 $line{'shelf'} = $element;
210 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
211 $line{'sortfield'}=$shelflist->{$element}->{'sortfield'};
212 $line{"viewcategory$shelflist->{$element}->{'category'}"} = 1;
213 $line{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser;
214 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
215 $line{'canmanage'} = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
216 $line{'firstname'} = $shelflist->{$element}->{'firstname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
217 $line{'surname'} = $shelflist->{$element}->{'surname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
218 $numberCanManage++ if $line{'canmanage'};
219 push( @shelvesloop, \%line );
223 shelvesloop => \@shelvesloop,
224 numberCanManage => $numberCanManage,
227 output_html_with_http_headers $query, $cookie, $template->output;
230 my $innertemplate = shift;
231 if ( my $newshelf = $query->param('addshelf') ) {
232 my $shelfnumber = AddShelf(
234 $query->param('owner'),
235 $query->param('category')
238 if ( $shelfnumber == -1 ) { #shelf already exists.
241 shelfnumber => $shelfnumber,
248 foreach ( $query->param() ) {
252 my ( $status, $count ) = DelShelf($delshelf);
254 $line{'status'} = $status;
255 $line{'count'} = $count;
259 #if the shelf is not deleted, %line points on null
260 push( @paramsloop, \%line );
262 $innertemplate->param( paramsloop => \@paramsloop );
263 my ($shelflist) = GetShelves( $loggedinuser, 2 );
266 foreach my $element ( sort keys %$shelflist ) {
268 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
269 $line{'toggle'} = $color;
270 $line{'shelf'} = $element;
271 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
272 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
273 push( @shelvesloop, \%line );
275 $innertemplate->param(
276 shelvesloop => \@shelvesloop,