From 527c4490998385e8f6d465cc13878e7d697c7f27 Mon Sep 17 00:00:00 2001 From: alaurin Date: Fri, 19 May 2006 09:52:54 +0000 Subject: [PATCH] committing new feature ip and printer management adding two fields in branches table (branchip,branchprinter) branchip : if the library enter an ip or ip range any librarian that connect from computer in this ip range will be temporarly affected to the corresponding branch . branchprinter : the library can select a default printer for a branch --- C4/Auth.pm | 35 ++++++++++--- C4/Context.pm | 11 +++- admin/branches.pl | 51 ++++++++++++++++--- .../intranet-tmpl/prog/en/admin/branches.tmpl | 23 +++++++++ 4 files changed, 105 insertions(+), 15 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 568d84090a..4a2735de9a 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -28,6 +28,7 @@ use C4::Context; use C4::Output; # to get the template use C4::Interface::CGI::Output; use C4::Circulation::Circ2; # getpatroninformation +use C4::Koha; # use Net::LDAP; # use Net::LDAP qw(:all); @@ -307,6 +308,7 @@ sub checkauth { $hash{branchname}, $hash{flags}, $hash{emailaddress}, + $hash{branchprinter} ); } my ($ip , $lasttime); @@ -391,22 +393,40 @@ sub checkauth { C4::Context->_unset_userenv($sessionID); } if ($return == 1){ - my ($bornum,$firstname,$surname,$userflags,$branchcode,$branchname,$emailaddress); - my $sth=$dbh->prepare("select borrowernumber, firstname, surname, flags, borrowers.branchcode, branches.branchname as branchname, email from borrowers left join branches on borrowers.branchcode=branches.branchcode where userid=?"); + my ($bornum,$firstname,$surname,$userflags,$branchcode,$branchname,$branchprinter,$emailaddress); + my $sth=$dbh->prepare("select borrowernumber, firstname, surname, flags, borrowers.branchcode, branches.branchname as branchname,branches.branchprinter as branchprinter, email from borrowers left join branches on borrowers.branchcode=branches.branchcode where userid=?"); $sth->execute($userid); - ($bornum,$firstname,$surname,$userflags,$branchcode,$branchname,$emailaddress) = $sth->fetchrow if ($sth->rows); + ($bornum,$firstname,$surname,$userflags,$branchcode,$branchname,$branchprinter,$emailaddress) = $sth->fetchrow if ($sth->rows); # warn "$cardnumber,$bornum,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress"; unless ($sth->rows){ - my $sth=$dbh->prepare("select borrowernumber, firstname, surname, flags, borrowers.branchcode, branches.branchname as branchname, email from borrowers left join branches on borrowers.branchcode=branches.branchcode where cardnumber=?"); + my $sth=$dbh->prepare("select borrowernumber, firstname, surname, flags, borrowers.branchcode, branches.branchname as branchname, branches.branchprinter as branchprinter, email from borrowers left join branches on borrowers.branchcode=branches.branchcode where cardnumber=?"); $sth->execute($cardnumber); - ($bornum,$firstname,$surname,$userflags,$branchcode,$branchcode,$emailaddress) = $sth->fetchrow if ($sth->rows); + ($bornum,$firstname,$surname,$userflags,$branchcode,$branchcode,$branchprinter, $emailaddress) = $sth->fetchrow if ($sth->rows); # warn "$cardnumber,$bornum,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress"; unless ($sth->rows){ $sth->execute($userid); - ($bornum,$firstname,$surname,$userflags,$branchcode,$emailaddress) = $sth->fetchrow if ($sth->rows); + ($bornum,$firstname,$surname,$userflags,$branchcode,$branchprinter,$emailaddress) = $sth->fetchrow if ($sth->rows); } # warn "$cardnumber,$bornum,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress"; } +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# new op dev : +# launch a sequence to check if we have a ip for the branch, if we have one we replace the branchcode of the userenv by the branch bound in the ip. + my $ip = $ENV{'REMOTE_ADDR'}; + my $branches = getbranches(); + my @branchesloop; + my $branchprinter; + foreach my $br (keys %$branches) { +# now we work with the treatment of ip + my $domain=$branches->{$br}->{branchip}; + if ($domain && $ip =~ /^$domain/){ + $branchcode = $branches->{$br}->{'branchcode'}; +# new op dev : add the branchprinter and branchname in the cookie + $branchprinter = $branches->{$br}->{'branchprinter'}; + $branchname = $branches->{$br}->{'branchname'}; + } + } + my $hash = C4::Context::set_userenv( $bornum, $userid, @@ -417,8 +437,9 @@ sub checkauth { $branchname, $userflags, $emailaddress, + $branchprinter, ); -# warn "$cardnumber,$bornum,$userid,$firstname,$surname,$userflags,$branchcode,$emailaddress"; + $envcookie=$query->cookie(-name => 'userenv', -value => $hash, -expires => ''); diff --git a/C4/Context.pm b/C4/Context.pm index 39b9ee61c0..f0b5339b46 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -744,7 +744,7 @@ set_userenv is called in Auth.pm =cut #' sub set_userenv{ - my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress)= @_; + my ($usernum, $userid, $usercnum, $userfirstname, $usersurname, $userbranch, $branchname, $userflags, $emailaddress,$branchprinter)= @_; my $var=$context->{"activeuser"}; my $cell = { "number" => $usernum, @@ -757,6 +757,7 @@ sub set_userenv{ "branchname" => $branchname, "flags" => $userflags, "emailaddress" => $emailaddress, + "branchprinter" => $branchprinter, }; $context->{userenv}->{$var} = $cell; return $cell; @@ -825,6 +826,14 @@ Andrew Arensburger =cut # $Log$ +# Revision 1.39 2006/05/19 09:52:54 alaurin +# committing new feature ip and printer management +# adding two fields in branches table (branchip,branchprinter) +# +# branchip : if the library enter an ip or ip range any librarian that connect from computer in this ip range will be temporarly affected to the corresponding branch . +# +# branchprinter : the library can select a default printer for a branch +# # Revision 1.38 2006/05/14 00:22:31 tgarip1957 # Adding support for getting details of different zebra servers # diff --git a/admin/branches.pl b/admin/branches.pl index 4ebf9d4011..32e5c3e6fa 100755 --- a/admin/branches.pl +++ b/admin/branches.pl @@ -51,6 +51,7 @@ use C4::Context; use C4::Output; use C4::Interface::CGI::Output; use HTML::Template; +use C4::Koha; # Fixed variables my $linecolor1='#ffffcc'; @@ -66,7 +67,7 @@ my $input = new CGI; my $branchcode=$input->param('branchcode'); my $branchname=$input->param('branchname'); my $categorycode = $input->param('categorycode'); -my $op = $input->param('op') || ''; +my $op = $input->param('op'); my ($template, $borrowernumber, $cookie) = get_template_and_user({template_name => "admin/branches.tmpl", @@ -166,7 +167,7 @@ if ($op eq 'add') { # html output functions.... sub default { - my ($message) = @_ || ""; + my ($message) = @_; heading("Branches"); $template->param('heading-branches-p' => 1); $template->param("$message" => 1); @@ -182,11 +183,33 @@ sub heading { sub editbranchform { # prepares the edit form... + +# initiate the scrolling-list to select the printers + my %env; + my $printers=getprinters(\%env); + my @printerloop; + my $printercount=0; + my $oldprinter; + my $CGIprinter; my ($branchcode) = @_; my $data; + if ($branchcode) { $data = getbranchinfo($branchcode); $data = $data->[0]; + # get the old printer of the branch + $oldprinter = $data->{'branchprinter'}; +# printer loop + foreach my $thisprinter (keys %$printers) { + my $selected = 1 if $oldprinter eq $printers->{$thisprinter}->{'printqueue'}; + my %row =(value => $thisprinter, + selected => $selected, + branchprinter => $printers->{$thisprinter}->{'printername'}, + ); + push @printerloop, \%row; + } + + $template->param(printerloop => \@printerloop ); $template->param(branchcode => $data->{'branchcode'}); $template->param(branchname => $data->{'branchname'}); $template->param(branchaddress1 => $data->{'branchaddress1'}); @@ -195,7 +218,19 @@ sub editbranchform { $template->param(branchphone => $data->{'branchphone'}); $template->param(branchfax => $data->{'branchfax'}); $template->param(branchemail => $data->{'branchemail'}); - } + $template->param(branchip => $data->{'branchip'}); + } + else { +# on add new branch mode, simple scrolling list + $CGIprinter=CGI::scrolling_list( -name => 'branchprinter', + -id => 'branchprinter', + -values => \@printerloop, + -size => 1, + -multiple => 0 ); + + } +# sending the cgiprinter to the template +# $template->param(printerloop => $CGIprinter); # make the checkboxs..... # @@ -261,7 +296,7 @@ sub branchinfotable { $branchinfo = getbranchinfo(); } my $toggle; - my $i=0; + my $i; my @loop_data =(); foreach my $branch (@$branchinfo) { ($i % 2) ? ($toggle = 1) : ($toggle = 0); @@ -292,7 +327,7 @@ sub branchinfotable { # Handle address fields separately my $address_empty_p = 1; for my $field ('branchaddress1', 'branchaddress2', 'branchaddress3', - 'branchphone', 'branchfax', 'branchemail') { + 'branchphone', 'branchfax', 'branchemail', 'branchip', 'branchprinter') { $row{$field} = $branch->{$field}; if ( $branch->{$field} ) { $address_empty_p = 0; @@ -329,6 +364,8 @@ sub branchinfotable { } my @branchcategories =(); my $catinfo = getcategoryinfo(); + my $toggle; + my $i = 0; foreach my $cat (@$catinfo) { ($i % 2) ? ($toggle = 1) : ($toggle = 0); push @branchcategories, { @@ -421,11 +458,11 @@ sub setbranchinfo { # sets the data from the editbranch form, and writes to the database... my ($data) = @_; my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("replace branches (branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail) values (?,?,?,?,?,?,?,?)"); + my $sth=$dbh->prepare("replace branches (branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail,branchip,branchprinter) values (?,?,?,?,?,?,?,?,?,?)"); $sth->execute(uc($data->{'branchcode'}), $data->{'branchname'}, $data->{'branchaddress1'}, $data->{'branchaddress2'}, $data->{'branchaddress3'}, $data->{'branchphone'}, - $data->{'branchfax'}, $data->{'branchemail'}); + $data->{'branchfax'}, $data->{'branchemail'}, $data->{'branchip'},$data->{'branchprinter'}); $sth->finish; # sort out the categories.... diff --git a/koha-tmpl/intranet-tmpl/prog/en/admin/branches.tmpl b/koha-tmpl/intranet-tmpl/prog/en/admin/branches.tmpl index 6869548dcf..7957ed2a66 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/admin/branches.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/admin/branches.tmpl @@ -57,6 +57,21 @@ E-mail " /> + + Branch IP + " /> + + + Branch Printer + + + +

@@ -84,6 +99,8 @@ Code Address Category + Branch IP + Branch Printer     @@ -118,6 +135,12 @@ + + + + + +
-- 2.39.5