Clean up before final commits
[koha_ffzg] / circ / branchtransfers.pl
index 6d06b1d..dd4db98 100755 (executable)
@@ -31,15 +31,15 @@ use C4::Auth;
 use C4::Interface::CGI::Output;
 use HTML::Template;
 use C4::Koha;
-
+use C4::Members;
 ###############################################
 # constants
 
 my %env;
-my $linecolor1= 0;
-my $linecolor2= 1;
+my $linecolor1='#ffffcc';
+my $linecolor2='white';
 
-my $branches = GetBranches();
+my $branches = getbranches();
 my $printers = getprinters(\%env);
 
 
@@ -63,14 +63,13 @@ my $reqmessage;
 my $cancelled;
 my $setwaiting;
 my $reqbrchname;
-my $allmessages;
-
+my $user=$query->param('loggedinuser');
 my $request=$query->param('request');
 my $borrnum = $query->param('borrowernumber');
 
 my $tobranchcd=$query->param('tobranchcd');
 my $frbranchcd='';
-
+my $dbh=C4::Context->dbh;
 ############
 # Deal with the requests....
 if ($request eq "KillWaiting") {
@@ -78,7 +77,6 @@ if ($request eq "KillWaiting") {
     CancelReserve(0, $item, $borrnum);
        $cancelled = 1;
        $reqmessage =1;
-       $allmessages = 1;
 }
 
 my $ignoreRs = 0;
@@ -89,14 +87,12 @@ if ($request eq "SetWaiting") {
     $ignoreRs = 1;
        $setwaiting = 1;
        $reqmessage =1;
-       $allmessages = 1;
 }
 if ($request eq 'KillReserved'){
     my $biblio = $query->param('biblionumber');
     CancelReserve($biblio, 0, $borrnum);
        $cancelled = 1;
        $reqmessage =1;
-       $allmessages = 1;
 }
 
 
@@ -119,17 +115,17 @@ my %transfereditems;
 my %frbranchcds;
 my %tobranchcds;
 my $color=$linecolor2;
-my $transfered;
+
 my $barcode = $query->param('barcode');
 if ($barcode) {
-
+       my $transfered;
        my $iteminformation;
        ($transfered, $messages, $iteminformation)
-                       = transferbook($tobranchcd, $barcode, $ignoreRs);
+                       = transferbook($tobranchcd, $barcode, $ignoreRs,$user);
        $found = $messages->{'ResFound'};
        if ($transfered) {
                my %item;
-               my $frbranchcd = $iteminformation->{'frbranchcd'};
+               my $frbranchcd = $iteminformation->{'holdingbranch'};
                if (not ($found)) {
                        ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
                        $item{'color'}=$color;
@@ -184,21 +180,13 @@ foreach ($query->param){
        push (@trsfitemloop, \%item);
 }
 
-my $title;
-my $surname;
-my $firstname;
-my $bornum;
-my $borphone;
-my $borstraddress;
-my $borcity;
-my $borzip;
-my $boremail;
+
+my $name;
 my $bornum;
 my $borcnum;
 my $itemnumber;
 my $biblionum;
 my $branchname;
-my $wastransferred;
 
 
 #####################
@@ -207,17 +195,8 @@ if ($found) {
     my $res = $messages->{'ResFound'};
        $branchname = $branches->{$res->{'branchcode'}}->{'branchname'};
        my ($borr) = getpatroninformation(\%env, $res->{'borrowernumber'}, 0);
-       $title = $borr->{'title'};
-       $surname = $borr->{'surname'};
-       $firstname = $borr->{'firstname'};
-       $bornum = $borr->{'borrowernumber'};
-    $borphone = $borr->{'phone'};
-    $borstraddress = $borr->{'streetaddress'};
-       $borcity = $borr->{'city'};
-       $borzip = $borr->{'zipcode'};
-       $boremail = $borr->{'emailadress'};
-       
-       #Hopefully, borr->{borrowernumber}=res->{borrowernumber}
+       $name = name($borr);
+       $bornum = $borr->{'borrowernumber'}; #Hopefully, borr->{borrowernumber}=res->{borrowernumber}
        $borcnum = $borr->{'cardnumber'};
        $itemnumber = $res->{'itemnumber'};
 
@@ -235,39 +214,33 @@ if ($found) {
 my @errmsgloop;
 foreach my $code (keys %$messages) {
        my %err;
-
+    $err{errbadcode} = ($code eq 'BadBarcode');
        if ($code eq 'BadBarcode') {
                $err{msg}=$messages->{'BadBarcode'};
-               $err{errbadcode} = 1;
-               $allmessages = 1;
        }
 
+    $err{errispermanent} = ($code eq 'IsPermanent');
     if ($code eq 'IsPermanent'){
-               $err{errispermanent} = 1;
                $err{msg} = $branches->{$messages->{'IsPermanent'}}->{'branchname'};
                # Here, msg contains the branchname
                # Not so satisfied with this... But should work
-               $allmessages = 1;
     }
     $err{errdesteqholding} = ($code eq 'DestinationEqualsHolding');
 
+       $err{errwasreturned} = ($code eq 'WasReturned');
        if ($code eq 'WasReturned') {
-               $err{errwasreturned} = 1;
-               $allmessages = 1;
                my ($borrowerinfo) = getpatroninformation(\%env, $messages->{'WasReturned'}, 0);
-               $title = $borrowerinfo->{'title'};
-               $surname = $borrowerinfo->{'surname'};
-               $firstname = $borrowerinfo->{'firstname'};
+               $name =name($borrowerinfo);
                $bornum =$borrowerinfo->{'borrowernumber'};
                $borcnum =$borrowerinfo->{'cardnumber'};
     }
-#    if ($code eq 'WasTransfered'){
+    if ($code eq 'WasTransfered'){
 # Put code here if you want to notify the user that item was transfered...
-#              $wastransferred = 1;
-#    }
+    }
        push (@errmsgloop, \%err);
 }
 
+
 #######################################################################################
 # Make the page .....
 my ($template, $borrowernumber, $cookie)
@@ -275,12 +248,8 @@ my ($template, $borrowernumber, $cookie)
                                                        query => $query,
                             type => "intranet",
                             authnotrequired => 0,
-                            flagsrequired => {circulate => 1},
+                            flagsrequired => {editcatalogue => 1},
                          });
-if($allmessages){
-       $template->param(allmessages => 1);
-}
-
 $template->param(      genbrname => $genbrname,
                                                                genprname => $genprname,
                                                                branch => $branch,
@@ -288,14 +257,7 @@ $template->param(  genbrname => $genbrname,
                                                                found => $found,
                                                                reserved => $reserved,
                                                                waiting => $waiting,
-                                                               title => $title,
-                                                               surname => $surname,
-                                                               firstname => $firstname,
-                                                               borphone => $borphone,
-                                                               borstraddress => $borstraddress,
-                                                               borcity => $borcity,
-                                                               borzip => $borzip,
-                                                               boremail => $boremail,
+                                                               name => $name,
                                                                bornum => $bornum,
                                                                borcnum => $borcnum,
                                                                branchname => $branchname,
@@ -306,13 +268,9 @@ $template->param(  genbrname => $genbrname,
                                                                reqmessage => $reqmessage,
                                                                cancelled => $cancelled,
                                                                setwaiting => $setwaiting,
-                                                               wastransferred => $wastransferred,
                                                                trsfitemloop => \@trsfitemloop,
                                                                branchoptionloop => \@branchoptionloop,
-                                                               errmsgloop => \@errmsgloop,
-                                                               intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
-               intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-               IntranetNav => C4::Context->preference("IntranetNav"),
+                                                               errmsgloop => \@errmsgloop
                                                        );
 output_html_with_http_headers $query, $cookie, $template->output;