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 C4::Members::Attributes qw(GetBorrowerAttributes);
20 use Digest::MD5 qw(md5_base64);
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",
32 flagsrequired => {borrowers => 1},
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');
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");
67 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
70 push(@errors,'BADUSERID');
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'});
98 ExtendedPatronAttributes => 1,
99 extendedattributes => $attributes
103 $template->param( othernames => $bor->{'othernames'},
104 surname => $bor->{'surname'},
105 firstname => $bor->{'firstname'},
106 borrowernumber => $bor->{'borrowernumber'},
107 cardnumber => $bor->{'cardnumber'},
108 categorycode => $bor->{'categorycode'},
109 category_type => $bor->{'category_type'},
110 categoryname => $bor->{'description'},
111 address => $bor->{'address'},
112 address2 => $bor->{'address2'},
113 city => $bor->{'city'},
114 state => $bor->{'state'},
115 zipcode => $bor->{'zipcode'},
116 country => $bor->{'country'},
117 phone => $bor->{'phone'},
118 email => $bor->{'email'},
119 branchcode => $bor->{'branchcode'},
120 branchname => GetBranchName($bor->{'branchcode'}),
121 userid => $bor->{'userid'},
122 destination => $destination,
123 is_child => ($bor->{'category_type'} eq 'C'),
124 activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
125 minPasswordLength => $minpw,
126 RoutingSerials => C4::Context->preference('RoutingSerials'),
129 if( scalar(@errors )){
130 $template->param( errormsg => 1 );
131 foreach my $error (@errors) {
132 $template->param($error) || $template->param( $error => 1);
137 output_html_with_http_headers $input, $cookie, $template->output;