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
15 use Digest
::MD5
qw(md5_base64);
19 my $theme = $input->param('theme') || "default";
20 # only used if allowthemeoverride is set
22 my ($template, $loggedinuser, $cookie, $staffflags)
23 = get_template_and_user
({template_name
=> "members/member-password.tmpl",
27 flagsrequired
=> {borrowers
=> 1},
32 $flagsrequired->{borrowers
}=1;
34 #my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired);
36 my $member=$input->param('member');
37 my $cardnumber = $input->param('cardnumber');
38 my $destination = $input->param('destination');
40 my ($bor)=GetMember
($member);
41 if(( $member ne $loggedinuser ) && ($bor->{'category_type'} eq 'S' ) ) {
42 $errormsg = 'NOPERMISSION' unless($staffflags->{'superlibrarian'} || $staffflags->{'staffaccess'} );
43 # need superlibrarian for koha-conf.xml fakeuser.
45 my $newpassword = $input->param('newpassword');
46 my $minpw = C4
::Context
->preference('minPasswordLength');
47 $errormsg = 'SHORTPASSWORD' if( $newpassword && $minpw & (length($newpassword) < $minpw ) );
49 if ( $newpassword && ! $errormsg ) {
50 my $digest=md5_base64
($input->param('newpassword'));
51 my $uid = $input->param('newuserid');
52 my $dbh=C4
::Context
->dbh;
53 if (changepassword
($uid,$member,$digest)) {
54 $template->param(newpassword
=> $newpassword);
55 if ($destination eq 'circ') {
56 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$cardnumber");
58 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
61 $errormsg = 'BADUSERID';
62 $template->param(othernames
=> $bor->{'othernames'},
63 surname
=> $bor->{'surname'},
64 firstname
=> $bor->{'firstname'},
65 userid
=> $bor->{'userid'},
66 defaultnewpassword
=> $newpassword
70 my $userid = $bor->{'userid'};
72 my $chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
73 my $length=int(rand(2))+4;
74 my $defaultnewpassword='';
75 for (my $i=0; $i<$length; $i++) {
76 $defaultnewpassword.=substr($chars, int(rand(length($chars))),1);
79 if ( $bor->{'category_type'} eq 'C') {
80 my ( $catcodes, $labels ) = GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
81 my $cnt = scalar(@
$catcodes);
82 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
83 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
86 $template->param( adultborrower
=> 1 ) if ( $bor->{'category_type'} eq 'A' );
87 my ($picture, $dberror) = GetPatronImage
($bor->{'cardnumber'});
88 $template->param( picture
=> 1 ) if $picture;
90 $template->param( othernames
=> $bor->{'othernames'},
91 surname
=> $bor->{'surname'},
92 firstname
=> $bor->{'firstname'},
93 borrowernumber
=> $bor->{'borrowernumber'},
94 cardnumber
=> $bor->{'cardnumber'},
95 categorycode
=> $bor->{'categorycode'},
96 category_type
=> $bor->{'category_type'},
97 category_description
=> $bor->{'description'},
98 address
=> $bor->{'address'},
99 address2
=> $bor->{'address2'},
100 city
=> $bor->{'city'},
101 zipcode
=> $bor->{'zipcode'},
102 phone
=> $bor->{'phone'},
103 email
=> $bor->{'email'},
104 branchcode
=> $bor->{'branchcode'},
105 userid
=> $bor->{'userid'},
106 destination
=> $destination,
107 is_child
=> ($bor->{'category_type'} eq 'C'),
108 defaultnewpassword
=> $defaultnewpassword
114 $template->param( member
=> $member,
115 errormsg
=> $errormsg,
117 minPasswordLength
=> $minpw );
119 output_html_with_http_headers
$input, $cookie, $template->output;