Bug 2593 : way to duplicate items
[koha.git] / members / member-password.pl
blobf18db8063735e12549f5af511612b1cca4ee74b7
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::Branch;
13 use C4::Circulation;
14 use CGI;
16 use Digest::MD5 qw(md5_base64);
18 my $input = new CGI;
20 my $theme = $input->param('theme') || "default";
21 # only used if allowthemeoverride is set
23 my ($template, $loggedinuser, $cookie, $staffflags)
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 });
32 my $flagsrequired;
33 $flagsrequired->{borrowers}=1;
35 #my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired);
37 my $member=$input->param('member');
38 my $cardnumber = $input->param('cardnumber');
39 my $destination = $input->param('destination');
40 my $errormsg;
41 my ($bor)=GetMember($member);
42 if(( $member ne $loggedinuser ) && ($bor->{'category_type'} eq 'S' ) ) {
43 $errormsg = 'NOPERMISSION' unless($staffflags->{'superlibrarian'} || $staffflags->{'staffaccess'} );
44 # need superlibrarian for koha-conf.xml fakeuser.
46 my $newpassword = $input->param('newpassword');
47 my $minpw = C4::Context->preference('minPasswordLength');
48 $errormsg = 'SHORTPASSWORD' if( $newpassword && $minpw && (length($newpassword) < $minpw ) );
50 if ( $newpassword && ! $errormsg ) {
51 my $digest=md5_base64($input->param('newpassword'));
52 my $uid = $input->param('newuserid');
53 my $dbh=C4::Context->dbh;
54 if (changepassword($uid,$member,$digest)) {
55 $template->param(newpassword => $newpassword);
56 if ($destination eq 'circ') {
57 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$cardnumber");
58 } else {
59 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
61 } else {
62 $errormsg = 'BADUSERID';
63 $template->param(othernames => $bor->{'othernames'},
64 surname => $bor->{'surname'},
65 firstname => $bor->{'firstname'},
66 userid => $bor->{'userid'},
67 defaultnewpassword => $newpassword
70 } else {
71 my $userid = $bor->{'userid'};
73 my $chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
74 my $length=int(rand(2))+4;
75 my $defaultnewpassword='';
76 for (my $i=0; $i<$length; $i++) {
77 $defaultnewpassword.=substr($chars, int(rand(length($chars))),1);
80 if ( $bor->{'category_type'} eq 'C') {
81 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
82 my $cnt = scalar(@$catcodes);
83 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
84 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
87 $template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
88 my ($picture, $dberror) = GetPatronImage($bor->{'cardnumber'});
89 $template->param( picture => 1 ) if $picture;
91 $template->param( othernames => $bor->{'othernames'},
92 surname => $bor->{'surname'},
93 firstname => $bor->{'firstname'},
94 borrowernumber => $bor->{'borrowernumber'},
95 cardnumber => $bor->{'cardnumber'},
96 categorycode => $bor->{'categorycode'},
97 category_type => $bor->{'category_type'},
98 categoryname => $bor->{'description'},
99 address => $bor->{'address'},
100 address2 => $bor->{'address2'},
101 city => $bor->{'city'},
102 zipcode => $bor->{'zipcode'},
103 phone => $bor->{'phone'},
104 email => $bor->{'email'},
105 branchcode => $bor->{'branchcode'},
106 branchname => GetBranchName($bor->{'branchcode'}),
107 userid => $bor->{'userid'},
108 destination => $destination,
109 is_child => ($bor->{'category_type'} eq 'C'),
110 defaultnewpassword => $defaultnewpassword
116 $template->param( member => $member,
117 errormsg => $errormsg,
118 $errormsg => 1 ,
119 minPasswordLength => $minpw );
121 output_html_with_http_headers $input, $cookie, $template->output;