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;
77 $debug = $ENV{DEBUG} || 0;
82 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
84 template_name => "virtualshelves/shelves.tmpl",
88 flagsrequired => { catalogue => 1 },
92 if ( $query->param('modifyshelfcontents') ) {
93 my $shelfnumber = $query->param('viewshelf');
94 my $barcode = $query->param('addbarcode');
95 my ($item) = GetItem( 0, $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
107 # getting the Shelves list
108 my $shelflist = GetShelves( $loggedinuser, 2 );
109 $template->param( { loggedinuser => $loggedinuser } );
110 my $op = $query->param('op');
113 if ( $op && ( $op eq 'modifsave' ) ) {
115 $query->param('shelfnumber'), $query->param('shelfname'),
116 $loggedinuser, $query->param('category'), $query->param('sortfield')
120 if ( $op && ( $op eq 'modif' ) ) {
121 my ( $shelfnumber, $shelfname, $owner, $category, $sortfield ) =
122 GetShelf( $query->param('shelf') );
125 shelfnumber => $shelfnumber,
126 shelfname => $shelfname,
127 "category$category" => 1,
128 "sort_$sortfield" => 1,
132 if ( $query->param('viewshelf') ) {
134 #check that the user can view the shelf
135 my $shelfnumber = $query->param('viewshelf');
136 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
137 my $items = GetShelfContents($shelfnumber);
139 shelfname => $shelflist->{$shelfnumber}->{'shelfname'},
140 shelfnumber => $shelfnumber,
141 viewshelf => $query->param('viewshelf'),
142 manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ),
148 if ( $query->param('shelves') ) {
149 if ( my $newshelf = $query->param('addshelf') ) {
150 my $shelfnumber = AddShelf(
152 $query->param('owner'),
153 $query->param('category')
156 if ( $shelfnumber == -1 ) { #shelf already exists.
159 shelfnumber => $shelfnumber,
164 print $query->redirect("/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=$shelfnumber");
168 foreach ( $query->param() ) {
172 my ( $status, $count ) = DelShelf($delshelf);
174 $line{'status'} = $status;
175 $line{'count'} = $count;
177 print $query->redirect("/cgi-bin/koha/virtualshelves/shelves.pl");
181 #if the shelf is not deleted, %line points on null
182 # push( @paramsloop, \%line );
184 $template->param( paramsloop => \@paramsloop );
185 my ($shelflist) = GetShelves( $loggedinuser, 2 );
188 foreach my $element ( sort keys %$shelflist ) {
190 (++$i % 2) and $line{'toggle'} = $i;
191 $line{'shelf'} = $element;
192 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
193 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
194 push( @shelvesloop, \%line );
197 shelvesloop => \@shelvesloop,
204 # rebuild shelflist in case a shelf has been added
205 $shelflist = GetShelves( $loggedinuser, 2 );
208 my $numberCanManage = 0;
210 foreach my $element ( sort keys %$shelflist ) {
212 (++$i % 2) and $line{'toggle'} = $i;
213 $line{'shelf'} = $element;
214 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
215 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
216 $line{'sortfield'} = $shelflist->{$element}->{'sortfield'};
217 $line{"viewcategory$shelflist->{$element}->{'category'}"} = 1;
218 $line{'canmanage'} = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
219 if ($shelflist->{$element}->{'owner'} eq $loggedinuser) {
222 $line{'firstname'} = $shelflist->{$element}->{'firstname'};
223 $line{'surname'} = $shelflist->{$element}->{'surname'} ;
225 $numberCanManage++ if $line{'canmanage'};
226 push( @shelvesloop, \%line );
230 shelvesloop => \@shelvesloop,
231 numberCanManage => $numberCanManage,
233 if ($template->param('viewshelf') or
234 $template->param( 'shelves' ) or
235 $template->param( 'edit' ) ) {
236 $template->param(vseflag => 1);
238 if ($template->param( 'shelves' ) or
239 $template->param( 'edit' ) ) {
240 $template->param( seflag => 1);
243 output_html_with_http_headers $query, $cookie, $template->output;
246 my $innertemplate = shift;
247 if ( my $newshelf = $query->param('addshelf') ) {
248 my $shelfnumber = AddShelf(
250 $query->param('owner'),
251 $query->param('category')
254 if ( $shelfnumber == -1 ) { #shelf already exists.
257 shelfnumber => $shelfnumber,
264 foreach ( $query->param() ) {
268 my ( $status, $count ) = DelShelf($delshelf);
270 $line{'status'} = $status;
271 $line{'count'} = $count;
275 #if the shelf is not deleted, %line points on null
276 push( @paramsloop, \%line );
278 $innertemplate->param( paramsloop => \@paramsloop );
279 my ($shelflist) = GetShelves( $loggedinuser, 2 );
282 foreach my $element ( sort keys %$shelflist ) {
284 (++$i % 2) and $line{'toggle'} = $i;
285 $line{'shelf'} = $element;
286 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
287 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
288 push( @shelvesloop, \%line );
290 $innertemplate->param(
291 shelvesloop => \@shelvesloop,