removing all useless %env / $env
[wip/koha-chris_n.git] / members / member-password.pl
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
6
7 use strict;
8 use C4::Auth;
9 use C4::Output;
10 use C4::Interface::CGI::Output;
11 use C4::Context;
12 use C4::Members;
13 use C4::Circulation;
14 use CGI;
15
16 use Digest::MD5 qw(md5_base64);
17
18 my $input = new CGI;
19
20 my $theme = $input->param('theme') || "default";
21                         # only used if allowthemeoverride is set
22
23 my ($template, $loggedinuser, $cookie)
24     = get_template_and_user({template_name => "members/member-password.tmpl",
25                              query => $input,
26                              type => "intranet",
27                              authnotrequired => 0,
28                              flagsrequired => {borrowers => 1},
29                              debug => 1,
30                              });
31
32 my $flagsrequired;
33 $flagsrequired->{borrowers}=1;
34 my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired);
35
36 my $member=$input->param('member');
37 my %member2;
38 $member2{'borrowernumber'}=$member;
39 # my $issues=GetBorrowerIssues(\%member2);
40 # my $i=0;
41 # foreach (sort keys %$issues) {
42 #     $i++;
43 # }
44
45 my ($bor,$flags)=GetMemberDetails( $member,'');
46 my $newpassword = $input->param('newpassword');
47
48 if ( $newpassword ) {
49         my $digest=md5_base64($input->param('newpassword'));
50         my $uid = $input->param('newuserid');
51         my $dbh=C4::Context->dbh;
52         if (changepassword($uid,$member,$digest)) {
53                 $template->param(newpassword => $newpassword);
54                 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
55         } else {
56         $template->param(othernames => $bor->{'othernames'},
57                                                 surname     => $bor->{'surname'},
58                                                 firstname   => $bor->{'firstname'},
59                                                 userid      => $bor->{'userid'},
60                                                 defaultnewpassword => $newpassword );
61         }
62 } else {
63     my $userid = $bor->{'userid'};
64
65     my $chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
66     my $length=int(rand(2))+4;
67     my $defaultnewpassword='';
68     for (my $i=0; $i<$length; $i++) {
69         $defaultnewpassword.=substr($chars, int(rand(length($chars))),1);
70     }
71         $template->param(       othernames => $bor->{'othernames'},
72                         surname     => $bor->{'surname'},
73                         firstname   => $bor->{'firstname'},
74                         userid      => $bor->{'userid'},
75                         defaultnewpassword => $defaultnewpassword );
76
77
78 }
79
80 $template->param( member => $member,
81                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
82                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
83                 IntranetNav => C4::Context->preference("IntranetNav"),
84                 );
85
86 output_html_with_http_headers $input, $cookie, $template->output;