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