Standardizing information shown in sidebar when patron-related pages are displayed...
[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::Context;
11 use C4::Members;
12 use C4::Circulation;
13 use CGI;
14
15 use Digest::MD5 qw(md5_base64);
16
17 my $input = new CGI;
18
19 my $theme = $input->param('theme') || "default";
20                         # only used if allowthemeoverride is set
21
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                              });
30
31 my $flagsrequired;
32 $flagsrequired->{borrowers}=1;
33 my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired);
34
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 # }
43
44 my ($bor,$flags)=GetMemberDetails( $member,'');
45 my $newpassword = $input->param('newpassword');
46
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 );
60         }
61 } else {
62     my $userid = $bor->{'userid'};
63
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);
69     }
70         $template->param(       othernames => $bor->{'othernames'},
71                         surname     => $bor->{'surname'},
72                         firstname   => $bor->{'firstname'},
73                         borrowernumber => $bor->{'borrowernumber'},
74                         cardnumber => $bor->{'cardnumber'},
75                     categorycode => $bor->{'categorycode'},
76                     category_type => $bor->{'category_type'},
77                     category_description => $bor->{'description'},
78                     address => $bor->{'address'},
79                         address2 => $bor->{'address2'},
80                     city => $bor->{'city'},
81                         zipcode => $bor->{'zipcode'},
82                         phone => $bor->{'phone'},
83                         email => $bor->{'email'},
84                     branchcode => $bor->{'branchcode'},
85                         userid      => $bor->{'userid'},
86                         defaultnewpassword => $defaultnewpassword );
87
88
89 }
90
91 output_html_with_http_headers $input, $cookie, $template->output;