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
17 use C4
::Members
::Attributes
qw(GetBorrowerAttributes);
19 use Digest
::MD5
qw(md5_base64);
23 my $theme = $input->param('theme') || "default";
24 # only used if allowthemeoverride is set
26 my ($template, $loggedinuser, $cookie, $staffflags)
27 = get_template_and_user
({template_name
=> "members/member-password.tmpl",
31 flagsrequired
=> {borrowers
=> 1},
36 $flagsrequired->{borrowers
}=1;
38 #my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired);
40 my $member=$input->param('member');
41 my $cardnumber = $input->param('cardnumber');
42 my $destination = $input->param('destination');
44 my ($bor)=GetMember
('borrowernumber' => $member);
45 if(( $member ne $loggedinuser ) && ($bor->{'category_type'} eq 'S' ) ) {
46 push(@errors,'NOPERMISSION') unless($staffflags->{'superlibrarian'} || $staffflags->{'staffaccess'} );
47 # need superlibrarian for koha-conf.xml fakeuser.
49 my $newpassword = $input->param('newpassword');
50 my $newpassword2 = $input->param('newpassword2');
52 push(@errors,'NOMATCH') if ( ( $newpassword && $newpassword2 ) && ($newpassword ne $newpassword2) );
54 my $minpw = C4
::Context
->preference('minPasswordLength');
55 push(@errors,'SHORTPASSWORD') if( $newpassword && $minpw && (length($newpassword) < $minpw ) );
57 if ( $newpassword && !scalar(@errors) ) {
58 my $digest=md5_base64
($input->param('newpassword'));
59 my $uid = $input->param('newuserid');
60 my $dbh=C4
::Context
->dbh;
61 if (changepassword
($uid,$member,$digest)) {
62 $template->param(newpassword
=> $newpassword);
63 if ($destination eq 'circ') {
64 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$cardnumber");
66 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
69 push(@errors,'BADUSERID');
72 my $userid = $bor->{'userid'};
74 my $chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
75 my $length=int(rand(2))+C4
::Context
->preference("minPasswordLength");
76 my $defaultnewpassword='';
77 for (my $i=0; $i<$length; $i++) {
78 $defaultnewpassword.=substr($chars, int(rand(length($chars))),1);
81 $template->param( defaultnewpassword
=> $defaultnewpassword );
83 if ( $bor->{'category_type'} eq 'C') {
84 my ( $catcodes, $labels ) = GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
85 my $cnt = scalar(@
$catcodes);
86 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
87 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
90 $template->param( adultborrower
=> 1 ) if ( $bor->{'category_type'} eq 'A' );
91 my ($picture, $dberror) = GetPatronImage
($bor->{'cardnumber'});
92 $template->param( picture
=> 1 ) if $picture;
94 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
95 my $attributes = GetBorrowerAttributes
($bor->{'borrowernumber'});
97 ExtendedPatronAttributes
=> 1,
98 extendedattributes
=> $attributes
102 $template->param( othernames
=> $bor->{'othernames'},
103 surname
=> $bor->{'surname'},
104 firstname
=> $bor->{'firstname'},
105 borrowernumber
=> $bor->{'borrowernumber'},
106 cardnumber
=> $bor->{'cardnumber'},
107 categorycode
=> $bor->{'categorycode'},
108 category_type
=> $bor->{'category_type'},
109 categoryname
=> $bor->{'description'},
110 address
=> $bor->{'address'},
111 address2
=> $bor->{'address2'},
112 city
=> $bor->{'city'},
113 state => $bor->{'state'},
114 zipcode
=> $bor->{'zipcode'},
115 country
=> $bor->{'country'},
116 phone
=> $bor->{'phone'},
117 email
=> $bor->{'email'},
118 branchcode
=> $bor->{'branchcode'},
119 branchname
=> GetBranchName
($bor->{'branchcode'}),
120 userid
=> $bor->{'userid'},
121 destination
=> $destination,
122 is_child
=> ($bor->{'category_type'} eq 'C'),
123 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
124 minPasswordLength
=> $minpw
127 if( scalar(@errors )){
128 $template->param( errormsg
=> 1 );
129 foreach my $error (@errors) {
130 $template->param($error) || $template->param( $error => 1);
135 output_html_with_http_headers
$input, $cookie, $template->output;