Languages.pm - BEGIN block VERSION and vars related to export.
[koha.git] / virtualshelves / shelves.pl
blob6c82e53ad085315c5f284f378b6406fe97e8eba0
1 #!/usr/bin/perl
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
11 # version.
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
21 =head1 NAME
23 shelves.pl
25 =head1 DESCRIPTION
27 this script is used to script to provide virtualshelf management
29 =head1 CGI PARAMETERS
31 =over 4
33 =item C<modifyshelfcontents>
35 if this script has to modify the shelve content.
37 =item C<shelfnumber>
39 to know on which shelve this script has to work.
41 =item C<addbarcode>
43 =item C<op>
45 op can be equals to:
46 * modifsave to save change on the shelves
47 * modif to change the template to allow to modify the shelves.
49 =item C<viewshelf>
51 to load the template with 'viewshelves param' which allow to read the shelves information.
53 =item C<shelves>
55 if equals to 1. then call the function shelves which add
56 or delete a shelf.
58 =item C<addshelf>
60 if the param shelves = 1 then addshelf must be equals to the name of the shelf to add.
62 =back
64 =cut
66 use strict;
67 use CGI;
68 use C4::VirtualShelves;
69 use C4::Biblio;
70 use C4::Items;
71 use C4::Auth;
72 use C4::Output;
74 my $query = new CGI;
76 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
78 template_name => "virtualshelves/shelves.tmpl",
79 query => $query,
80 type => "intranet",
81 authnotrequired => 0,
82 flagsrequired => { catalogue => 1 },
86 if ( $query->param('modifyshelfcontents') ) {
87 my $shelfnumber = $query->param('viewshelf');
88 my $barcode = $query->param('addbarcode');
89 my ($item) = GetItem( 0, $barcode );
90 my ($biblio) = GetBiblioFromItemNumber($item->{'itemnumber'});
91 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) {
92 AddToShelf( $biblio->{'biblionumber'}, $shelfnumber );
93 foreach ( $query->param ) {
94 if (/REM-(\d*)/) {
95 my $biblionumber = $1;
96 DelFromShelf( $biblionumber, $shelfnumber );
102 # getting the Shelves list
103 my $shelflist = GetShelves( $loggedinuser, 2 );
104 $template->param( { loggedinuser => $loggedinuser } );
105 my $op = $query->param('op');
107 SWITCH: {
108 if ( $op && ( $op eq 'modifsave' ) ) {
109 ModShelf(
110 $query->param('shelfnumber'), $query->param('shelfname'),
111 $loggedinuser, $query->param('category'), $query->param('sortfield')
113 last SWITCH;
115 if ( $op && ( $op eq 'modif' ) ) {
116 my ( $shelfnumber, $shelfname, $owner, $category, $sortfield ) =
117 GetShelf( $query->param('shelf') );
118 $template->param(
119 edit => 1,
120 shelfnumber => $shelfnumber,
121 shelfname => $shelfname,
122 "category$category" => 1,
123 "sort_$sortfield" => 1,
125 last SWITCH;
127 if ( $query->param('viewshelf') ) {
129 #check that the user can view the shelf
130 my $shelfnumber = $query->param('viewshelf');
131 if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) {
132 my $items = GetShelfContents($shelfnumber);
133 $template->param(
134 shelfname => $shelflist->{$shelfnumber}->{'shelfname'},
135 shelfnumber => $shelfnumber,
136 viewshelf => $query->param('viewshelf'),
137 manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ),
138 itemsloop => $items,
141 last SWITCH;
143 if ( $query->param('shelves') ) {
144 if ( my $newshelf = $query->param('addshelf') ) {
145 my $shelfnumber = AddShelf(
146 $newshelf,
147 $query->param('owner'),
148 $query->param('category')
151 if ( $shelfnumber == -1 ) { #shelf already exists.
152 $template->param(
154 shelfnumber => $shelfnumber,
155 already => 1
159 print $query->redirect("/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=$shelfnumber");
160 exit;
162 my @paramsloop;
163 foreach ( $query->param() ) {
164 my %line;
165 if (/DEL-(\d+)/) {
166 my $delshelf = $1;
167 my ( $status, $count ) = DelShelf($delshelf);
168 if ($status) {
169 $line{'status'} = $status;
170 $line{'count'} = $count;
172 print $query->redirect("/cgi-bin/koha/virtualshelves/shelves.pl");
173 exit;
176 #if the shelf is not deleted, %line points on null
177 # push( @paramsloop, \%line );
179 $template->param( paramsloop => \@paramsloop );
180 my ($shelflist) = GetShelves( $loggedinuser, 2 );
181 my $color = '';
182 my @shelvesloop;
183 foreach my $element ( sort keys %$shelflist ) {
184 my %line;
185 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
186 $line{'toggle'} = $color;
187 $line{'shelf'} = $element;
188 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
189 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
190 push( @shelvesloop, \%line );
192 $template->param(
193 shelvesloop => \@shelvesloop,
194 shelves => 1,
196 last SWITCH;
200 # rebuild shelflist in case a shelf has been added
201 $shelflist = GetShelves( $loggedinuser, 2 );
202 my $color = '';
203 my @shelvesloop;
204 my $numberCanManage = 0;
206 foreach my $element ( sort keys %$shelflist ) {
207 my %line;
208 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
209 $line{'toggle'} = $color;
210 $line{'shelf'} = $element;
211 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
212 $line{'sortfield'}=$shelflist->{$element}->{'sortfield'};
213 $line{"viewcategory$shelflist->{$element}->{'category'}"} = 1;
214 $line{'mine'} = 1 if $shelflist->{$element}->{'owner'} eq $loggedinuser;
215 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
216 $line{'canmanage'} = ShelfPossibleAction( $loggedinuser, $element, 'manage' );
217 $line{'firstname'} = $shelflist->{$element}->{'firstname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
218 $line{'surname'} = $shelflist->{$element}->{'surname'} unless $shelflist->{$element}->{'owner'} eq $loggedinuser;
219 $numberCanManage++ if $line{'canmanage'};
220 push( @shelvesloop, \%line );
223 $template->param(
224 shelvesloop => \@shelvesloop,
225 numberCanManage => $numberCanManage,
228 output_html_with_http_headers $query, $cookie, $template->output;
230 sub shelves {
231 my $innertemplate = shift;
232 if ( my $newshelf = $query->param('addshelf') ) {
233 my $shelfnumber = AddShelf(
234 $newshelf,
235 $query->param('owner'),
236 $query->param('category')
239 if ( $shelfnumber == -1 ) { #shelf already exists.
240 $template->param(
242 shelfnumber => $shelfnumber,
243 already => 1
248 my @paramsloop;
249 foreach ( $query->param() ) {
250 my %line;
251 if (/DEL-(\d+)/) {
252 my $delshelf = $1;
253 my ( $status, $count ) = DelShelf($delshelf);
254 if ($status) {
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 );
265 my $color = '';
266 my @shelvesloop;
267 foreach my $element ( sort keys %$shelflist ) {
268 my %line;
269 ( $color eq 1 ) ? ( $color = 0 ) : ( $color = 1 );
270 $line{'toggle'} = $color;
271 $line{'shelf'} = $element;
272 $line{'shelfname'} = $shelflist->{$element}->{'shelfname'};
273 $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'};
274 push( @shelvesloop, \%line );
276 $innertemplate->param(
277 shelvesloop => \@shelvesloop,
278 shelves => 1,