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 bookshelf 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::Circulation::Circ2;
72 use C4::Interface::CGI::Output;
76 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
78 template_name => "bookshelves/shelves.tmpl",
82 flagsrequired => { catalogue => 1 },
86 if ( $query->param('modifyshelfcontents') ) {
87 my $shelfnumber = $query->param('viewshelf');
88 my $barcode = $query->param('addbarcode');
89 my ($item) = getiteminformation( 0, $barcode );
90 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) {
91 AddToShelf( $item->{'itemnumber'}, $shelfnumber );
92 foreach ( $query->param ) {
95 DelFromShelf( $itemnumber, $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')
114 if ( $op && ( $op eq 'modif' ) ) {
115 my ( $shelfnumber, $shelfname, $owner, $category ) =
116 GetShelf( $query->param('shelf') );
119 shelfnumber => $shelfnumber,
120 shelfname => $shelfname,
121 "category$category" => 1
124 # editshelf($query->param('shelf'));
127 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,
160 foreach ( $query->param() ) {
164 my ( $status, $count ) = DelShelf($delshelf);
166 $line{'status'} = $status;
167 $line{'count'} = $count;
171 #if the shelf is not deleted, %line points on null
172 push( @paramsloop, \%line );
174 $template->param( paramsloop => \@paramsloop );
175 my ($shelflist) = GetShelves( $loggedinuser, 2 );
178 foreach my $element ( sort keys %$shelflist ) {
180 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
181 $line{'toggle'} = $color;
182 $line{'shelf'} = $element;
183 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
184 $line{'shelfbookcount'} = $shelflist->{$element}->{'count'};
185 push( @shelvesloop, \%line );
188 shelvesloop => \@shelvesloop,
196 GetShelves( $loggedinuser, 2 )
197 ; # rebuild shelflist in case a shelf has been added
201 my $numberCanManage = 0;
203 foreach my $element ( sort keys %$shelflist ) {
205 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
206 $line{'toggle'} = $color;
207 $line{'shelf'} = $element;
208 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
209 $line{ "category" . $shelflist->{$element}->{'category'} } = 1;
210 $line{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser;
211 $line{'shelfbookcount'} = $shelflist->{$element}->{'count'};
212 $line{'canmanage'} = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
213 $line{'firstname'} = $shelflist->{$element}->{'firstname'}
214 unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
215 $line{'surname'} = $shelflist->{$element}->{'surname'}
216 unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
218 $numberCanManage++ if $line{'canmanage'};
220 push( @shelvesloop, \%line );
224 shelvesloop => \@shelvesloop,
225 numberCanManage => $numberCanManage,
228 output_html_with_http_headers $query, $cookie, $template->output;
231 my $innertemplate = shift;
232 if ( my $newshelf = $query->param('addshelf') ) {
233 my $shelfnumber = AddShelf(
235 $query->param('owner'),
236 $query->param('category')
239 if ( $shelfnumber == -1 ) { #shelf already exists.
242 shelfnumber => $shelfnumber,
249 foreach ( $query->param() ) {
253 my ( $status, $count ) = DelShelf($delshelf);
255 $line{'status'} = $status;
256 $line{'count'} = $count;
260 #if the shelf is not deleted, %line points on null
261 push( @paramsloop, \%line );
263 $innertemplate->param( paramsloop => \@paramsloop );
264 my ($shelflist) = GetShelves( $loggedinuser, 2 );
267 foreach my $element ( sort keys %$shelflist ) {
269 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
270 $line{'toggle'} = $color;
271 $line{'shelf'} = $element;
272 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
273 $line{'shelfbookcount'} = $shelflist->{$element}->{'count'};
274 push( @shelvesloop, \%line );
276 $innertemplate->param(
277 shelvesloop => \@shelvesloop,
284 # Revision 1.11 2007/03/09 14:32:26 tipaul
285 # rel_3_0 moved to HEAD
287 # Revision 1.9.2.9 2007/02/05 15:54:30 toins
288 # don't display "remove selected shelves" if the user logged has no shelf.
290 # Revision 1.9.2.8 2006/12/15 17:36:57 toins
291 # - some change on the html param.
292 # - Writing directly the code of a sub called only once.
293 # - adding syspref: BiblioDefaultView.
295 # Revision 1.9.2.7 2006/12/14 17:22:55 toins
296 # bookshelves work perfectly with mod_perl and are cleaned.
298 # Revision 1.9.2.6 2006/12/13 10:06:05 toins
299 # fix a mod_perl specific bug.
301 # Revision 1.9.2.5 2006/12/11 17:10:06 toins
302 # fixing some bugs on bookshelves.
304 # Revision 1.9.2.4 2006/11/30 18:23:51 toins
305 # theses scripts don't need to use C4::Search.
307 # Revision 1.9.2.3 2006/10/30 09:50:45 tipaul
308 # better perl writting
310 # Revision 1.9.2.2 2006/10/17 07:59:35 toins