bug fixing :
[koha-ffzg.git] / admin / branches.pl
index 1f3f2ca..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';
@@ -69,7 +70,7 @@ my $categorycode = $input->param('categorycode');
 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,
@@ -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.....
     #
@@ -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;
@@ -423,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....