renamed CheckSpecificUserPermissions to GranularPermissions
[koha_fer] / members / memberentry.pl
index 67a9ccf..5cc8c00 100755 (executable)
@@ -21,7 +21,6 @@
 use strict;
 
 # external modules
-use Date::Calc qw/Today/;
 use CGI;
 # use Digest::MD5 qw(md5_base64);
 
@@ -36,6 +35,8 @@ use C4::Input;
 use C4::Log;
 use C4::Branch; # GetBranches
 
+#use Smart::Comments;
+
 use vars qw($debug);
 
 BEGIN {
@@ -68,6 +69,8 @@ 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;
@@ -93,6 +96,7 @@ $template->param("checked" => 1) if ($nodouble eq 1);
 ($borrower_data = GetMember($borrowernumber,'borrowernumber')) if ($op eq 'modify' or $op eq 'save');
 my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'};
 my $category_type = $input->param('category_type');
+my $new_c_type = $category_type; #if we have input param, then we've already chosen the cat_type.
 unless ($category_type or !($categorycode)){
   my $borrowercategory= GetBorrowercategory($categorycode);
   $category_type = $borrowercategory->{'category_type'};
@@ -163,12 +167,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 ''){
-  if ($select_city){
-    my ($borrower_city,$borrower_zipcode)=&getzipnamecity($select_city);
-    $newdata{'city'}= $borrower_city;
-    $newdata{'zipcode'}=$borrower_zipcode;
-    }
+    $newdata{'city'}= $city;
+    $newdata{'zipcode'}=$zipcode; 
 }
+
 #builds default userid
 if ( (defined $newdata{'userid'}) && ($newdata{'userid'} eq '')){
   my $onefirstnameletter = substr($data{'firstname'},0,1);
@@ -187,7 +189,7 @@ if ($op eq 'save' || $op eq 'insert'){
     my $age = GetAge($newdata{dateofbirth});
     my $borrowercategory=GetBorrowercategory($newdata{'categorycode'});   
        my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'});
-    if (($age > $high) or ($age < $low)) {
+    if (($high && ($age > $high)) or ($age < $low)) {
       push @errors, 'ERROR_age_limitations';
          $template->param('ERROR_age_limitations' => "$low to $high");
     }
@@ -209,7 +211,7 @@ if ($op eq 'save' || $op eq 'insert'){
 
 if ($op eq 'modify' || $op eq 'insert'){
   unless ($newdata{'dateexpiry'}){
-       my $arg2 = $newdata{'dateenrolled'} || sprintf('%04d-%02d-%02d', Today());
+       my $arg2 = $newdata{'dateenrolled'} || C4::Dates->today('iso');
     $newdata{'dateexpiry'} = GetExpiryDate($newdata{'categorycode'},$arg2);
   }
 }
@@ -264,7 +266,7 @@ if (C4::Context->preference("IndependantBranches")) {
   }
 }
 if ($op eq 'add'){
-       my $arg2 = $newdata{'dateenrolled'} || sprintf('%04d-%02d-%02d', Today()); 
+       my $arg2 = $newdata{'dateenrolled'} || C4::Dates->today('iso');
        $data{'dateexpiry'} = GetExpiryDate($newdata{'categorycode'},$arg2);
        $template->param( updtype => 'I',step_1=>1,step_2=>1,step_3=>1);
        
@@ -299,7 +301,7 @@ if ($ethnicitycategoriescount>=0) {
 }
 
 my @typeloop;
-foreach (qw(C A S P I)){
+foreach ( ($new_c_type) ? ($new_c_type) : qw(C A S P I X)){
        my $action="WHERE category_type=?";
        ($categories,$labels)=GetborCatFromCatType($_,$action);
        my @categoryloop;
@@ -469,8 +471,7 @@ if ($nok) {
   #Formatting data for display    
   
 if ($data{'dateenrolled'} eq ''){
-  my $today = sprintf('%04d-%02d-%02d', Today());      # ISO format
-  $data{'dateenrolled'}=$today;
+  $data{'dateenrolled'}=C4::Dates->today('iso');
 }
 if (C4::Context->preference('uppercasesurnames')) {
        $data{'surname'}    =uc($data{'surname'}    );
@@ -481,7 +482,7 @@ foreach (qw(dateenrolled dateexpiry dateofbirth)) {
        $template->param( $_ => $data{$_});
 }
 
-$template->param( "showguarantor"  => ($category_type=~/A|I|S/) ? 0 : 1); # associate with step to know where you are
+$template->param( "showguarantor"  => ($category_type=~/A|I|S|X/) ? 0 : 1); # associate with step to know where you are
 $debug and warn "memberentry step: $step";
 $template->param(%data);
 $template->param( "step_$step"  => 1) if $step;        # associate with step to know where u are