Fix errors on Korean translation files
[koha.git] / members / member-password.pl
blobeb37b999459ff2b0171f521da422a7912c412830
1 #!/usr/bin/perl
2 #script to set the password, and optionally a userid, for a borrower
3 #written 2/5/00
4 #by chris@katipo.co.nz
5 #converted to using templates 3/16/03 by mwhansen@hmc.edu
7 use strict;
8 use warnings;
10 use C4::Auth;
11 use Koha::AuthUtils;
12 use C4::Output;
13 use C4::Context;
14 use C4::Members;
15 use C4::Branch;
16 use C4::Circulation;
17 use CGI;
18 use C4::Members::Attributes qw(GetBorrowerAttributes);
20 use Digest::MD5 qw(md5_base64);
22 my $input = new CGI;
24 my $theme = $input->param('theme') || "default";
25 # only used if allowthemeoverride is set
27 my ($template, $loggedinuser, $cookie, $staffflags)
28 = get_template_and_user({template_name => "members/member-password.tt",
29 query => $input,
30 type => "intranet",
31 authnotrequired => 0,
32 flagsrequired => {borrowers => 1},
33 debug => 1,
34 });
36 my $flagsrequired;
37 $flagsrequired->{borrowers}=1;
39 #my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired, 'intranet');
41 my $member=$input->param('member');
42 my $cardnumber = $input->param('cardnumber');
43 my $destination = $input->param('destination');
44 my @errors;
45 my ($bor)=GetMember('borrowernumber' => $member);
46 if(( $member ne $loggedinuser ) && ($bor->{'category_type'} eq 'S' ) ) {
47 push(@errors,'NOPERMISSION') unless($staffflags->{'superlibrarian'} || $staffflags->{'staffaccess'} );
48 # need superlibrarian for koha-conf.xml fakeuser.
50 my $newpassword = $input->param('newpassword');
51 my $newpassword2 = $input->param('newpassword2');
53 push(@errors,'NOMATCH') if ( ( $newpassword && $newpassword2 ) && ($newpassword ne $newpassword2) );
55 my $minpw = C4::Context->preference('minPasswordLength');
56 push(@errors,'SHORTPASSWORD') if( $newpassword && $minpw && (length($newpassword) < $minpw ) );
58 if ( $newpassword && !scalar(@errors) ) {
59 my $digest=Koha::AuthUtils::hash_password($input->param('newpassword'));
60 my $uid = $input->param('newuserid');
61 my $dbh=C4::Context->dbh;
62 if (changepassword($uid,$member,$digest)) {
63 $template->param(newpassword => $newpassword);
64 if ($destination eq 'circ') {
65 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$cardnumber");
66 } else {
67 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
69 } else {
70 push(@errors,'BADUSERID');
72 } else {
73 my $userid = $bor->{'userid'};
75 my $chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
76 my $length=int(rand(2))+C4::Context->preference("minPasswordLength");
77 my $defaultnewpassword='';
78 for (my $i=0; $i<$length; $i++) {
79 $defaultnewpassword.=substr($chars, int(rand(length($chars))),1);
82 $template->param( defaultnewpassword => $defaultnewpassword );
84 if ( $bor->{'category_type'} eq 'C') {
85 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
86 my $cnt = scalar(@$catcodes);
87 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
88 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
91 $template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
92 my ($picture, $dberror) = GetPatronImage($bor->{'borrowernumber'});
93 $template->param( picture => 1 ) if $picture;
95 if (C4::Context->preference('ExtendedPatronAttributes')) {
96 my $attributes = GetBorrowerAttributes($bor->{'borrowernumber'});
97 $template->param(
98 ExtendedPatronAttributes => 1,
99 extendedattributes => $attributes
103 # Computes full borrower address
104 my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $bor->{streettype} );
105 my $address = $bor->{'streetnumber'} . " $roadtype " . $bor->{'address'};
107 $template->param( othernames => $bor->{'othernames'},
108 surname => $bor->{'surname'},
109 firstname => $bor->{'firstname'},
110 borrowernumber => $bor->{'borrowernumber'},
111 cardnumber => $bor->{'cardnumber'},
112 categorycode => $bor->{'categorycode'},
113 category_type => $bor->{'category_type'},
114 categoryname => $bor->{'description'},
115 address => $address,
116 address2 => $bor->{'address2'},
117 city => $bor->{'city'},
118 state => $bor->{'state'},
119 zipcode => $bor->{'zipcode'},
120 country => $bor->{'country'},
121 phone => $bor->{'phone'},
122 phonepro => $bor->{'phonepro'},
123 mobile => $bor->{'mobile'},
124 email => $bor->{'email'},
125 emailpro => $bor->{'emailpro'},
126 branchcode => $bor->{'branchcode'},
127 branchname => GetBranchName($bor->{'branchcode'}),
128 userid => $bor->{'userid'},
129 destination => $destination,
130 is_child => ($bor->{'category_type'} eq 'C'),
131 activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
132 minPasswordLength => $minpw,
133 RoutingSerials => C4::Context->preference('RoutingSerials'),
136 if( scalar(@errors )){
137 $template->param( errormsg => 1 );
138 foreach my $error (@errors) {
139 $template->param($error) || $template->param( $error => 1);
144 output_html_with_http_headers $input, $cookie, $template->output;