road to 3.0 : updating a biblio in zebra seems to work. Still working on it, there...
[koha-ffzg.git] / members / memberentry.pl
index d09cd88..035e9aa 100755 (executable)
@@ -88,6 +88,7 @@ if ($op eq 'add' or $op eq 'modify') {
                        push @errors, "ERROR_invalid_cardnumber";
                }
        }
+
        if ($data{'sex'} eq '' && $categorycode ne "I"){
                push @errors, "ERROR_gender";
                $nok=1;
@@ -108,6 +109,15 @@ if ($op eq 'add' or $op eq 'modify') {
                push @errors, "ERROR_city";
                $nok=1;
        }
+       if (C4::Context->preference("IndependantBranches")) {
+               my $userenv = C4::Context->userenv;
+               if ($userenv->{flags} != 1){
+                       unless ($userenv->{branch} eq $data{'branchcode'}){
+                               push @errors, "ERROR_branch";
+                               $nok=1;
+                       }
+               }
+       }
        if ($nok) {
                foreach my $error (@errors) {
                        $template->param( $error => 1);
@@ -148,12 +158,21 @@ if ($delete){
        } else {
                $data=borrdata('',$borrowernumber);
        }
+       if (C4::Context->preference("IndependantBranches")) {
+               my $userenv = C4::Context->userenv;
+               if ($userenv->{flags} != 1 && $data->{branchcode}){
+                       unless ($userenv->{branch} eq $data->{'branchcode'}){
+                               print $input->redirect("/cgi-bin/koha/members/members-home.pl");
+                       }
+               }
+       }
        if ($actionType eq 'Add'){
                $template->param( updtype => 'I');
        } else {
                $template->param( updtype => 'M');
        }
-       my $cardnumber=C4::Members::fixup_cardnumber($data->{'cardnumber'});
+       my $cardnumber=$data->{'cardnumber'};
+       $cardnumber=fixup_cardnumber($data->{'cardnumber'}) if $actionType eq 'Add';
        if ($data->{'sex'} eq 'F'){
                $template->param(female => 1);
        }
@@ -180,9 +199,10 @@ if ($delete){
        my @relshipdata;
        while (@relationships) {
                my $relship = shift @relationships;
+               next unless $relship;
                my %row = ('relationship' => $relship);
                if ($data->{'altrelationship'} eq $relship) {
-                       $row{'selected'}=' selected';
+                       $row{'selected'}=' selected = "selected"';
                } else {
                        $row{'selected'}='';
                }
@@ -201,11 +221,11 @@ if ($delete){
                        'name'  => $flags{$key}[0],
                        'html'  => $flags{$key}[1]);
        if ($data->{$key}) {
-               $row{'yes'}=' checked';
+               $row{'yes'}=' checked="checked"';
                $row{'no'}='';
        } else {
                $row{'yes'}='';
-               $row{'no'}=' checked';
+               $row{'no'}=' checked="checked"';
        }
        push(@flagdata, \%row);
        }
@@ -221,10 +241,19 @@ if ($delete){
        my @select_branch;
        my %select_branches;
        my $branches=getbranches();
+       my $default;
        foreach my $branch (keys %$branches) {
-               push @select_branch, $branch;
-               $select_branches{$branch} = $branches->{$branch}->{'branchname'};
+               if ((not C4::Context->preference("IndependantBranches")) || (C4::Context->userenv->{'flags'} == 1)) {
+                       push @select_branch, $branch;
+                       $select_branches{$branch} = $branches->{$branch}->{'branchname'};
+                       $default = $data->{'branchcode'};
+               } else {
+                               push @select_branch, $branch if ($branch eq C4::Context->userenv->{'branch'});
+                               $select_branches{$branch} = $branches->{$branch}->{'branchname'} if ($branch eq C4::Context->userenv->{'branch'});
+                               $default = C4::Context->userenv->{'branch'};
+               }
        }
+       
        my $CGIbranch=CGI::scrolling_list( -name     => 'branchcode',
                                -id => 'branchcode',
                                -values   => \@select_branch,
@@ -232,7 +261,35 @@ if ($delete){
                                -labels   => \%select_branches,
                                -size     => 1,
                                -multiple => 0 );
+       
+       my $CGIsort1 = buildCGIsort("Bsort1","sort1",$data->{'sort1'});
+       if ($CGIsort1) {
+               $template->param(CGIsort1 => $CGIsort1);
+       } else {
+               $template->param( sort1 => $data->{'sort1'});
+       }
+       
+       my $CGIsort2 = buildCGIsort("Bsort2","sort2",$data->{'sort2'});
+       if ($CGIsort2) {
+               $template->param(CGIsort2 =>$CGIsort2);
+       } else {
+               $template->param( sort2 => $data->{'sort2'});
+       }
+
+       my $CGIsort1 = buildCGIsort("Bsort1","sort1",$data->{'sort1'});
+       if ($CGIsort1) {
+               $template->param(CGIsort1 => $CGIsort1);
+       } else {
+               $template->param( sort1 => $data->{'sort1'});
+       }
 
+       my $CGIsort2 = buildCGIsort("Bsort2","sort2",$data->{'sort2'});
+       if ($CGIsort2) {
+               $template->param(CGIsort2 =>$CGIsort2);
+       } else {
+               $template->param( sort2 => $data->{'sort2'});
+       }
+       
        $template->param(       actionType              => $actionType,
                                destination => $destination,
                                borrowernumber          => $borrowernumber,
@@ -265,8 +322,6 @@ if ($delete){
                                expiry          => format_date($data->{'expiry'}),
                                cardnumber      => $cardnumber,
                                dateofbirth     => $data->{'dateofbirth'},
-                               sort1 => $data->{'sort1'},
-                               sort2 => $data->{'sort2'},
                                dateformat      => display_date_format(),
                                modify          => $modify,
                                CGIbranch => $CGIbranch);