bug 2609: display correct requested title
[koha_fer] / members / memberentry.pl
index 9d282cd..dba1818 100755 (executable)
@@ -70,8 +70,6 @@ my $check_member=$input->param('check_member');
 my $name_city=$input->param('name_city');
 my $nodouble=$input->param('nodouble');
 my $select_city=$input->param('select_city');
-my $zipcode=$input->param('zipcode');
-my $city=$input->param('city');
 my $nok=$input->param('nok');
 my $guarantorinfo=$input->param('guarantorinfo');
 my $step=$input->param('step') || 0;
@@ -161,9 +159,9 @@ if (($category_type eq 'C' || $category_type eq 'P') and $guarantorid ne '' ){
   my $guarantordata=GetMember($guarantorid);
   $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
   if (($data{'contactname'} eq '' or $data{'contactname'} ne $guarantordata->{'surname'})) {
-    $data{'contactfirstname'}= $guarantordata->{'firstname'}; 
+    $data{'contactfirstname'}= $guarantordata->{'firstname'};
     $data{'contactname'}     = $guarantordata->{'surname'};
-    $data{'contacttitle'}    = $guarantordata->{'title'};  
+    $data{'contacttitle'}    = $guarantordata->{'title'};
          foreach (qw(streetnumber address streettype address2 zipcode city phone phonepro mobile fax email emailpro branchcode)) {
                $data{$_} = $guarantordata->{$_};
        }
@@ -171,9 +169,10 @@ if (($category_type eq 'C' || $category_type eq 'P') and $guarantorid ne '' ){
 }
 
 ###############test to take the right zipcode and city name ##############
-if ( $guarantorid eq ''){
-    $newdata{'city'}= $city;
-    $newdata{'zipcode'}=$zipcode; 
+if ($guarantorid eq '') {
+    # set only if parameter was passed from the form
+    $newdata{'city'}    = $input->param('city')    if defined($input->param('city'));
+    $newdata{'zipcode'} = $input->param('zipcode') if defined($input->param('zipcode'));
 }
 
 #builds default userid
@@ -351,8 +350,8 @@ if ($ethnicitycategoriescount>=0) {
 }
 
 my @typeloop;
-foreach ( ($category_type) ? ($category_type) : qw(C A S P I X)){
-       my $action="WHERE category_type=?";
+foreach (qw(C A S P I X)) {
+    my $action="WHERE category_type=?";
        ($categories,$labels)=GetborCatFromCatType($_,$action);
        my @categoryloop;
        foreach my $cat (@$categories){
@@ -380,7 +379,7 @@ my($cityid);
 $template->param( city_cgipopup => 1) if ($cityid );
 my $citypopup = CGI::popup_menu(-name=>'select_city',
         -id => 'select_city',
-        -values=>$name_city,
+        '-values' =>$cityid,
         -labels=>$name_city,
         -default=>$default_city,
         );  
@@ -455,7 +454,7 @@ my $onlymine=(C4::Context->preference('IndependantBranches') &&
 my $branches=GetBranches($onlymine);
 my $default;
 
-foreach my $branch (sort keys %$branches) {
+for my $branch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
     push @select_branch,$branch;
     $select_branches{$branch} = $branches->{$branch}->{'branchname'};
     $default = C4::Context->userenv->{'branch'} if (C4::Context->userenv && C4::Context->userenv->{'branch'});
@@ -556,7 +555,7 @@ $template->param(
   nodouble  => $nodouble,
   borrowernumber  => $borrowernumber,#register number
   "contacttitle_".$data{'contacttitle'} => "SELECTED" ,
-  guarantorid => $guarantorid,
+  guarantorid => $borrower_data ? $borrower_data->{'guarantorid'} : $guarantorid,
   ethcatpopup => $ethcatpopup,
   relshiploop => \@relshipdata,
   citypopup => $citypopup,