Merge commit 'pianohacker-koha/prefs-submit' into master
[koha.git] / rotating_collections / transferCollection.pl
1 #!/usr/bin/perl
2 use strict;
3 require Exporter;
4
5 use C4::Output;
6 use C4::Auth;
7 use C4::Context;
8 use C4::RotatingCollections;
9 use C4::Branch;
10
11 use CGI;
12
13 my $query = new CGI;
14
15 my $colId = $query->param('colId');
16 my $toBranch = $query->param('toBranch');
17
18 my ($template, $loggedinuser, $cookie)
19     = get_template_and_user({template_name => "rotating_collections/transferCollection.tmpl",
20                              query => $query,
21                              type => "intranet",
22                              authnotrequired => 1,
23                              flagsrequired => {parameters => 1},
24                              debug => 1,
25                              });
26
27 ## Transfer collection
28 my ( $success, $errorCode, $errorMessage );
29 if ( $toBranch ) {
30   ( $success, $errorCode, $errorMessage ) = TransferCollection( $colId, $toBranch );
31
32   if ( $success ) {
33     $template->param( transferSuccess => 1 );
34   } else {
35     $template->param( transferFailure => 1,
36                       errorCode => $errorCode,
37                       errorMessage => $errorMessage
38     );
39   }
40 }
41
42 ## Set up the toBranch select options
43 my $branches = GetBranches();
44 my @branchoptionloop;
45 foreach my $br (keys %$branches) {
46   my %branch;
47   $branch{code}=$br;
48   $branch{name}=$branches->{$br}->{'branchname'};
49   push (@branchoptionloop, \%branch);
50 }
51     
52 ## Get data about collection
53 my ( $colId, $colTitle, $colDesc, $colBranchcode ) = GetCollection( $colId );                                
54 $template->param(
55                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
56                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
57                 IntranetNav => C4::Context->preference("IntranetNav"),
58                                   
59                 colId => $colId,
60                 colTitle => $colTitle,
61                 colDesc => $colDesc,
62                 colBranchcode => $colBranchcode,
63                 branchoptionloop => \@branchoptionloop
64                 );
65                                                                                                 
66 output_html_with_http_headers $query, $cookie, $template->output;