bug fixing :
[koha-ffzg.git] / admin / branches.pl
index fd804b1..4e730e8 100755 (executable)
@@ -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,10 +67,10 @@ 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 => "parameters/branches.tmpl",
+    = get_template_and_user({template_name => "admin/branches.tmpl",
                             query => $input,
                             type => "intranet",
                             authnotrequired => 0,
@@ -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,20 +183,52 @@ 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}->{'printqueue'},
+                       );
+               push @printerloop, \%row;
+               }
+               
+               $template->param(printerloop => \@printerloop );
                $template->param(branchcode => $data->{'branchcode'});
-               $template->param(branchname => $data->{'branchname'});
+               $template->param(branch_name => $data->{'branchname'});
                $template->param(branchaddress1 => $data->{'branchaddress1'});
                $template->param(branchaddress2 => $data->{'branchaddress2'});
                $template->param(branchaddress3 => $data->{'branchaddress3'});
                $template->param(branchphone => $data->{'branchphone'});
                $template->param(branchfax => $data->{'branchfax'});
                $template->param(branchemail => $data->{'branchemail'});
-    }
+               $template->param(branchip => $data->{'branchip'});
+       }
+       else { #case of an add branch select printer
+               foreach my $thisprinter (keys %$printers) {
+                       my %row =(value => $thisprinter,
+                               branchprinter => $printers->{$thisprinter}->{'printqueue'},
+                       );
+               push @printerloop, \%row;
+               }
+       $template->param(printerloop => \@printerloop );        
+       }
 
     # make the checkboxs.....
     #
@@ -261,7 +294,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 +325,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 +362,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 +456,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....