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.
69 use C4::VirtualShelves;
77 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
79 template_name => "opac-shelves.tmpl",
86 if ( $query->param('modifyshelfcontents') ) {
87 my $shelfnumber = $query->param('viewshelf');
88 my $barcode = $query->param('addbarcode');
89 my ($item) = GetItemnumberFromBarcode($barcode);
90 my ($biblio) = GetBiblioFromItemNumber($item->{'itemnumber'});
91 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) {
92 AddToShelf( $biblio->{'biblionumber'}, $shelfnumber );
93 foreach ( $query->param ) {
95 my $biblionumber = $1;
96 if ( $query->param('remove') eq "on" ) {
97 DelFromShelf( $biblionumber, $shelfnumber );
104 # set the default tab, etc.
105 my $shelf_type = $query->param('display');
106 if ((!$shelf_type) || ($shelf_type eq 'privateshelves')) {
107 $template->param(showprivateshelves => 1);
108 } elsif ($shelf_type eq 'publicshelves') {
109 $template->param(showpublicshelves => 1);
112 # getting the Shelves list
113 my $shelflist = GetShelves( $loggedinuser, 2 );
114 $template->param( { loggedinuser => $loggedinuser } );
115 my $op = $query->param('op');
118 if ( $op && ( $op eq 'modifsave' ) ) {
120 $query->param('shelfnumber'), $query->param('shelfname'),
121 $loggedinuser, $query->param('category'), $query->param('sortfield')
125 if ( $op && ( $op eq 'modif' ) ) {
126 my ( $shelfnumber, $shelfname, $owner, $category, $sortfield ) =
127 GetShelf( $query->param('shelf') );
130 shelfnumber => $shelfnumber,
131 shelfname => $shelfname,
132 "category$category" => 1,
133 "sort_$sortfield" => 1,
136 # editshelf($query->param('shelf'));
139 if ( $query->param('viewshelf') ) {
140 #check that the user can view the shelf
141 my $shelfnumber = $query->param('viewshelf');
142 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
143 my $items = GetShelfContents($shelfnumber);
145 shelfname => $shelflist->{$shelfnumber}->{'shelfname'},
146 shelfnumber => $shelfnumber,
147 viewshelf => $query->param('viewshelf'),
148 manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ),
154 if ( $query->param('shelves') ) {
155 if ( my $newshelf = $query->param('addshelf') ) {
156 my $shelfnumber = AddShelf(
158 $query->param('owner'),
159 $query->param('category')
162 if ( $shelfnumber == -1 ) { #shelf already exists.
165 shelfnumber => $shelfnumber,
172 foreach ( $query->param() ) {
176 my ( $status, $count ) = DelShelf($delshelf);
178 $line{'status'} = $status;
179 $line{'count'} = $count;
183 #if the shelf is not deleted, %line points on null
184 push( @paramsloop, \%line );
186 $template->param( paramsloop => \@paramsloop );
187 my ($shelflist) = GetShelves( $loggedinuser, 2 );
190 foreach my $element ( sort keys %$shelflist ) {
192 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
193 $line{'toggle'} = $color;
194 $line{'shelf'} = $element;
195 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
196 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
197 push( @shelvesloop, \%line );
200 shelvesloop => \@shelvesloop,
207 # rebuild shelflist in case a shelf has been added
208 ($shelflist) = GetShelves( $loggedinuser, 2 ) ;
213 foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflist->{$b}->{'shelfname'}) } keys %$shelflist) {
216 ($color eq 0) ? ($color=1) : ($color=0);
217 if ($shelflist->{$element}->{'category'} eq 2) {
218 $line{'color'}= $color;
219 $line{'shelf'}=$element;
220 $line{'shelfname'}=$shelflist->{$element}->{'shelfname'};
221 $line{'sortfield'}=$shelflist->{$element}->{'sortfield'};
222 $line{"category".$shelflist->{$element}->{'category'}} = 1;
223 $line{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser;
224 $line{'shelfbookcount'}=$shelflist->{$element}->{'count'};
225 $line{'canmanage'} = ShelfPossibleAction($loggedinuser,$element,'manage');
226 $line{'firstname'}=$shelflist->{$element}->{'firstname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
227 $line{'surname'}=$shelflist->{$element}->{'surname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
229 push (@shelvesloop, \%line);
230 } elsif ($shelflist->{$element}->{'category'} eq 1) {
231 $linepriv{'color'}= $color;
232 $linepriv{'shelf'}=$element;
233 $linepriv{'shelfname'}=$shelflist->{$element}->{'shelfname'};
234 $linepriv{'sortfield'}=$shelflist->{$element}->{'sortfield'};
235 $linepriv{"category".$shelflist->{$element}->{'category'}} = 1;
236 $linepriv{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser;
237 $linepriv{'shelfbookcount'}=$shelflist->{$element}->{'count'};
238 $linepriv{'canmanage'} = ShelfPossibleAction($loggedinuser,$element,'manage');
239 $linepriv{'firstname'}=$shelflist->{$element}->{'firstname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
240 $linepriv{'surname'}=$shelflist->{$element}->{'surname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
241 push (@shelveslooppriv, \%linepriv);
246 shelveslooppriv => \@shelveslooppriv,
247 shelvesloop => \@shelvesloop,
248 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
251 output_html_with_http_headers $query, $cookie, $template->output;
256 # Revision 1.12 2007/04/24 13:54:29 hdl
257 # functions that were in C4::Interface::CGI::Output are now in C4::Output.
258 # So this implies quite a change for files.
259 # Sorry about conflicts which will be caused.
260 # directory Interface::CGI should now be dropped.
261 # I noticed that many scripts (reports ones, but also some circ/stats.pl or opac-topissues) still use Date::Manip.
263 # Revision 1.11 2007/04/17 08:52:19 tipaul
264 # circulation cleaning continued: bufixing
266 # Revision 1.10 2007/04/04 16:46:23 tipaul
267 # HUGE COMMIT : code cleaning circulation.
269 # some stuff to do, i'll write a mail on koha-devel NOW !
271 # Revision 1.9 2007/03/09 15:12:54 tipaul
272 # rel_3_0 moved to HEAD
274 # Revision 1.8.2.12 2007/01/15 17:19:30 toins
275 # enable to add checked items to a shelf.
276 # Some display enhancements.
278 # Revision 1.8.2.11 2007/01/10 10:52:58 toins
279 # adding syspref directly to Auth.pm instead of to the template.
281 # Revision 1.8.2.10 2007/01/10 10:12:48 toins
282 # Adding OpacTopissue, OpacCloud, OpacAuthorithies to the template->param.
285 # Revision 1.8.2.9 2006/12/15 17:43:24 toins
286 # sync with intranet.
288 # Revision 1.8.2.8 2006/12/14 17:59:17 toins
289 # add the link to "BiblioDefaultView systempref" and not to opac-detail.pl
291 # Revision 1.8.2.7 2006/12/14 17:22:55 toins
292 # virtualshelves work perfectly with mod_perl and are cleaned.
294 # Revision 1.8.2.6 2006/12/14 16:04:25 toins
295 # sync with intranet.
297 # Revision 1.8.2.5 2006/12/11 17:10:06 toins
298 # fixing some bugs on virtualshelves.
300 # Revision 1.8.2.4 2006/12/07 15:42:15 toins
301 # synching opac & intranet.
302 # fix some broken link & bugs.
303 # removing warn compilation.
305 # Revision 1.8.2.3 2006/11/30 18:23:51 toins
306 # theses scripts don't need to use C4::Search.