2 #script to set the password, and optionally a userid, for a borrower
5 #converted to using templates 3/16/03 by mwhansen@hmc.edu
18 use Digest
::MD5
qw(md5_base64);
22 my $theme = $input->param('theme') || "default";
23 # only used if allowthemeoverride is set
25 my ($template, $loggedinuser, $cookie, $staffflags)
26 = get_template_and_user
({template_name
=> "members/member-password.tmpl",
30 flagsrequired
=> {borrowers
=> 1},
35 $flagsrequired->{borrowers
}=1;
37 #my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired);
39 my $member=$input->param('member');
40 my $cardnumber = $input->param('cardnumber');
41 my $destination = $input->param('destination');
43 my ($bor)=GetMember
('borrowernumber' => $member);
44 if(( $member ne $loggedinuser ) && ($bor->{'category_type'} eq 'S' ) ) {
45 $errormsg = 'NOPERMISSION' unless($staffflags->{'superlibrarian'} || $staffflags->{'staffaccess'} );
46 # need superlibrarian for koha-conf.xml fakeuser.
48 my $newpassword = $input->param('newpassword');
49 my $minpw = C4
::Context
->preference('minPasswordLength');
50 $errormsg = 'SHORTPASSWORD' if( $newpassword && $minpw && (length($newpassword) < $minpw ) );
52 if ( $newpassword && ! $errormsg ) {
53 my $digest=md5_base64
($input->param('newpassword'));
54 my $uid = $input->param('newuserid');
55 my $dbh=C4
::Context
->dbh;
56 if (changepassword
($uid,$member,$digest)) {
57 $template->param(newpassword
=> $newpassword);
58 if ($destination eq 'circ') {
59 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$cardnumber");
61 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
64 $errormsg = 'BADUSERID';
65 $template->param(othernames
=> $bor->{'othernames'},
66 surname
=> $bor->{'surname'},
67 firstname
=> $bor->{'firstname'},
68 userid
=> $bor->{'userid'},
69 defaultnewpassword
=> $newpassword
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 if ( $bor->{'category_type'} eq 'C') {
83 my ( $catcodes, $labels ) = GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
84 my $cnt = scalar(@
$catcodes);
85 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
86 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
89 $template->param( adultborrower
=> 1 ) if ( $bor->{'category_type'} eq 'A' );
90 my ($picture, $dberror) = GetPatronImage
($bor->{'cardnumber'});
91 $template->param( picture
=> 1 ) if $picture;
93 $template->param( othernames
=> $bor->{'othernames'},
94 surname
=> $bor->{'surname'},
95 firstname
=> $bor->{'firstname'},
96 borrowernumber
=> $bor->{'borrowernumber'},
97 cardnumber
=> $bor->{'cardnumber'},
98 categorycode
=> $bor->{'categorycode'},
99 category_type
=> $bor->{'category_type'},
100 categoryname
=> $bor->{'description'},
101 address
=> $bor->{'address'},
102 address2
=> $bor->{'address2'},
103 city
=> $bor->{'city'},
104 zipcode
=> $bor->{'zipcode'},
105 country
=> $bor->{'country'},
106 phone
=> $bor->{'phone'},
107 email
=> $bor->{'email'},
108 branchcode
=> $bor->{'branchcode'},
109 branchname
=> GetBranchName
($bor->{'branchcode'}),
110 userid
=> $bor->{'userid'},
111 destination
=> $destination,
112 is_child
=> ($bor->{'category_type'} eq 'C'),
113 defaultnewpassword
=> $defaultnewpassword
119 $template->param( member
=> $member,
120 errormsg
=> $errormsg,
122 minPasswordLength
=> $minpw );
124 output_html_with_http_headers
$input, $cookie, $template->output;