/[A3C]/lib/A3C/Model/User.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/A3C/Model/User.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 33 by dpavlin, Tue Mar 18 19:22:30 2008 UTC revision 42 by dpavlin, Sun Mar 30 16:58:21 2008 UTC
# Line 64  use A3C::Record schema { Line 64  use A3C::Record schema {
64    
65          column hrEduPersonUniqueNumber =>          column hrEduPersonUniqueNumber =>
66  #               is mandatory,  #               is mandatory,
67                  label is _('JMBG');                  label is _('Unique number');
68    
69          column hrEduPersonDateOfBirth =>          column hrEduPersonDateOfBirth =>
70                  type is 'date',                  type is 'date',
# Line 88  use A3C::Record schema { Line 88  use A3C::Record schema {
88                  label is _('Tip administratora'),                  label is _('Tip administratora'),
89                  valid are [ '', 'AS', 'AI', 'AR', 'AHU' ];                  valid are [ '', 'AS', 'AI', 'AR', 'AHU' ];
90    
91            column hrEduPersonHomeOrg =>
92                    label is _('Oznaka matične ustanove'),
93                    hint is 'CARNet',
94                    is mandatory;
95    
96          column hrEduPersonProfessionalStatus =>          column hrEduPersonProfessionalStatus =>
97                  label is _('Stručni status'),                  label is _('Stručni status'),
98                  valid are [                  valid are [
# Line 148  use A3C::Record schema { Line 153  use A3C::Record schema {
153                  ],                  ],
154                  default is '';                  default is '';
155    
156          column organization =>  #       column organization =>
157                  refers_to A3C::Model::Organization by 'id',  #               refers_to A3C::Model::Organization by 'id',
158                  is mandatory;  #               is mandatory;
159    
160          column hrEduPersonAffiliation =>          column hrEduPersonAffiliation =>
161                  label is _('Povezanost s ustanovom'),                  label is _('Povezanost s ustanovom'),
# Line 340  sub validate_telephoneNumber { Line 345  sub validate_telephoneNumber {
345    
346          return ( 1, 'OK' );          return ( 1, 'OK' );
347  }  }
348    
349    =head2 hrEduPersonUniqueNumber
350    
351    Check if JMBG is valid
352    
353    =cut
354    
355    sub validate_hrEduPersonUniqueNumber {
356            my ( $self, $value ) = @_;
357    
358            if ( $value =~ m/^JMBG:\s+(\d+)$/ ) {
359    
360                    my $jmbg = $1;
361    
362                    return ( 0, _('JMBG must have 13 digits') ) unless length($jmbg) == 13;
363    
364                    sub digit_at {
365                            my ($jmbg,$pos) = @_;
366                            return ord(substr($jmbg,$pos,1)) - ord('0');
367                    }
368    
369                    my $sum;
370                    my $fact = 7;
371    
372                    foreach my $i ( 0 .. 11 ) {
373                            my $c = digit_at( $jmbg, $i );
374                            $sum += $c * $fact;
375    #                       warn "## $c * $fact => $sum\n";
376                            $fact--;
377                            $fact = 7 if $fact == 1;
378                    }
379    
380                    my $ost = $sum % 11;
381                    $ost = 11 - $ost if $ost > 1;
382    
383                    return ( 0, _("JMBG is invalid") ) if $ost != digit_at( $jmbg, 12 );
384            }
385    
386            return ( 1, 'OK' );
387    }
388    
389  =head2 canonicalize_hrEduPersonExpireDate  =head2 canonicalize_hrEduPersonExpireDate
390    

Legend:
Removed from v.33  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26