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
10 use C4::Interface::CGI::Output;
13 use C4::Circulation::Circ2;
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)
24 = get_template_and_user({template_name => "members/member-password.tmpl",
28 flagsrequired => {borrowers => 1},
33 $flagsrequired->{borrowers}=1;
34 my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired);
36 my $member=$input->param('member');
38 $env{'nottodayissues'}=1;
40 $member2{'borrowernumber'}=$member;
41 my $issues=currentissues(\%env,\%member2);
43 foreach (sort keys %$issues) {
47 my ($bor,$flags)=getpatroninformation(\%env, $member,'');
48 my $newpassword = $input->param('newpassword');
51 my $digest=md5_base64($input->param('newpassword'));
52 my $uid = $input->param('newuserid');
53 my $dbh=C4::Context->dbh;
55 #Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
56 #Then we need to tell the user and have them create a new one.
57 my $sth2=$dbh->prepare("select * from borrowers where userid=? and borrowernumber != ?");
58 $sth2->execute($uid,$member);
60 if ( ($uid ne '') && ($sth2->fetchrow) ) {
61 #The userid exists so we should display a warning.
63 $template->param( warn => $warn,
64 othernames => $bor->{'othernames'},
65 surname => $bor->{'surname'},
66 firstname => $bor->{'firstname'},
67 userid => $bor->{'userid'},
68 defaultnewpassword => $newpassword );
70 #Everything is good so we can update the information.
71 my $sth=$dbh->prepare("update borrowers set userid=?, password=? where borrowernumber=?");
72 $sth->execute($uid, $digest, $member);
73 $template->param(newpassword => $newpassword);
77 my $userid = $bor->{'userid'};
79 my $chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
80 my $length=int(rand(2))+4;
81 my $defaultnewpassword='';
82 for (my $i=0; $i<$length; $i++) {
83 $defaultnewpassword.=substr($chars, int(rand(length($chars))),1);
85 $template->param( othernames => $bor->{'othernames'},
86 surname => $bor->{'surname'},
87 firstname => $bor->{'firstname'},
88 userid => $bor->{'userid'},
89 defaultnewpassword => $defaultnewpassword );
94 $template->param( member => $member );
96 output_html_with_http_headers $input, $cookie, $template->output;