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
This commit is contained in:
alaurin 2006-05-19 09:52:54 +00:00
parent 68924c5e6b
commit 527c449099
4 changed files with 105 additions and 15 deletions

View File

@ -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 => '');

View File

@ -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 <arensb at ooblick dot com>
=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
#

View File

@ -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....

View File

@ -57,6 +57,21 @@
<td>E-mail</td>
<td><input type="text" name="branchemail" value="<!-- TMPL_VAR name="branchemail" escape="HTML" -->" /></td>
</tr>
<tr>
<td>Branch IP</td>
<td><input type="text" name="branchip" value="<!-- TMPL_VAR name="branchip" escape="HTML" -->" /></td>
</tr>
<tr>
<td>Branch Printer</td>
<td>
<select id="branchprinter" name="branchprinter">
<option value="">None</option>
<!-- TMPL_LOOP NAME="printerloop" -->
<option value="<!-- TMPL_VAR NAME="value" -->"<!-- TMPL_IF NAME="selected" --> selected="selected"<!-- /TMPL_IF -->><!-- TMPL_VAR NAME="branchprinter" --></option>
<!-- /TMPL_LOOP -->
</select>
</td>
</tr>
</table><p><input type="submit" value="Submit" /></p>
</form>
<!-- /TMPL_IF -->
@ -84,6 +99,8 @@
<th>Code</th>
<th>Address</th>
<th>Category</th>
<th>Branch IP</th>
<th>Branch Printer</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
@ -118,6 +135,12 @@
<!-- /TMPL_LOOP -->
<!-- /TMPL_IF -->
</td>
<td>
<!-- TMPL_VAR NAME="branchip" -->
</td>
<td>
<!-- TMPL_VAR NAME="branchprinter" -->
</td>
<td>
<form action="<!-- TMPL_VAR name=action -->" method="post">
<input type="hidden" name="op" value="edit" />