bug-1490, fixed seasonal-year drop-box
[koha.git] / members / member-password.pl
blobd600c07b5f7656b0534af4e293d748bcf34ef9a5
1 #!/usr/bin/perl
2 #script to set the password, and optionally a userid, for a borrower
3 #written 2/5/00
4 #by chris@katipo.co.nz
5 #converted to using templates 3/16/03 by mwhansen@hmc.edu
7 use strict;
8 use C4::Auth;
9 use C4::Output;
10 use C4::Context;
11 use C4::Members;
12 use C4::Circulation;
13 use CGI;
15 use Digest::MD5 qw(md5_base64);
17 my $input = new CGI;
19 my $theme = $input->param('theme') || "default";
20 # only used if allowthemeoverride is set
22 my ($template, $loggedinuser, $cookie)
23 = get_template_and_user({template_name => "members/member-password.tmpl",
24 query => $input,
25 type => "intranet",
26 authnotrequired => 0,
27 flagsrequired => {borrowers => 1},
28 debug => 1,
29 });
31 my $flagsrequired;
32 $flagsrequired->{borrowers}=1;
33 my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired);
35 my $member=$input->param('member');
36 my %member2;
37 $member2{'borrowernumber'}=$member;
38 # my $issues=GetBorrowerIssues(\%member2);
39 # my $i=0;
40 # foreach (sort keys %$issues) {
41 # $i++;
42 # }
44 my ($bor,$flags)=GetMemberDetails( $member,'');
45 my $newpassword = $input->param('newpassword');
47 if ( $newpassword ) {
48 my $digest=md5_base64($input->param('newpassword'));
49 my $uid = $input->param('newuserid');
50 my $dbh=C4::Context->dbh;
51 if (changepassword($uid,$member,$digest)) {
52 $template->param(newpassword => $newpassword);
53 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
54 } else {
55 $template->param(othernames => $bor->{'othernames'},
56 surname => $bor->{'surname'},
57 firstname => $bor->{'firstname'},
58 userid => $bor->{'userid'},
59 defaultnewpassword => $newpassword );
61 } else {
62 my $userid = $bor->{'userid'};
64 my $chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
65 my $length=int(rand(2))+4;
66 my $defaultnewpassword='';
67 for (my $i=0; $i<$length; $i++) {
68 $defaultnewpassword.=substr($chars, int(rand(length($chars))),1);
70 $template->param( othernames => $bor->{'othernames'},
71 surname => $bor->{'surname'},
72 firstname => $bor->{'firstname'},
73 borrowernumber => $bor->{'borrowernumber'},
74 userid => $bor->{'userid'},
75 defaultnewpassword => $defaultnewpassword );
80 $template->param( member => $member,
82 output_html_with_http_headers $input, $cookie, $template->output;