Bug 4276: Proposed fix for "Related Subjects" links in Opac.
[koha.git] / labels / label-edit-template.pl
index b4ec950..47b6bd7 100755 (executable)
@@ -6,7 +6,7 @@ use C4::Auth;
 use C4::Context;
 use C4::Output;
 use C4::Labels;
-use HTML::Template;
+use HTML::Template::Pro;
 use POSIX;
 
 # use Data::Dumper;
@@ -24,6 +24,7 @@ my $columns    = $query->param('columns');
 my $rows       = $query->param('rows');
 my $colgap     = $query->param('colgap');
 my $rowgap     = $query->param('rowgap');
+my $prof_id    = $query->param('prof_id');
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
@@ -37,6 +38,30 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 );
 
 my $tmpl = GetSingleLabelTemplate($tmpl_id);
+my $curprof = GetAssociatedProfile($tmpl_id);
+my @prof = GetAllPrinterProfiles();
+my @proflist;
+
+# Generate an array of hashes containing possible profiles for given template and mark the currently associated one...
+
+foreach my $prof (@prof) {
+    if ( $prof->{'tmpl_id'} eq $tmpl->{'tmpl_id'} && $prof->{'prof_id'} eq $curprof->{'prof_id'} ) {
+        push ( @proflist,  {prof_id         => $prof->{'prof_id'},
+                            printername     => $prof->{'printername'},
+                            paper_bin       => $prof->{'paper_bin'},
+                            selected        => 1} );
+    }
+    
+    elsif ( $prof->{'tmpl_id'} eq $tmpl->{'tmpl_id'} ) {
+        push ( @proflist,  {prof_id         => $prof->{'prof_id'},
+                            printername     => $prof->{'printername'},
+                            paper_bin       => $prof->{'paper_bin'}} );
+    }
+    
+    elsif ( !$prof ) {
+        undef @proflist;
+    }
+}
 
 my @units = (
     { unit => 'INCH',  desc => 'Inches' },
@@ -51,9 +76,32 @@ foreach my $unit (@units) {
     }
 }
 
+my @fonts = (        #FIXME: There is probably a way to discover what additional fonts are installed on a user's system and generate this list dynamically...
+    { font => 'TR',     name => 'Times Roman' },
+    { font => 'TB',     name => 'Times Bold' },
+    { font => 'TI',     name => 'Times Italic' },
+    { font => 'TBI',    name => 'Times Bold Italic' },
+    { font => 'C',      name => 'Courier' },
+    { font => 'CB',     name => 'Courier Bold' },
+    { font => 'CO',     name => 'Courier Oblique' },
+    { font => 'CBO',    name => 'Courier Bold Oblique' },
+    { font => 'H',      name => 'Helvetica' },
+    { font => 'HB',     name => 'Helvetica Bold' },
+    { font => 'HO',     name => 'Helvetica Oblique' },
+    { font => 'HBO',    name => 'Helvetica Bold Oblique' },
+);
+
+foreach my $font (@fonts) {
+    if ( $font->{'font'} eq $tmpl->{'font'} ) {
+        $font->{'selected'} = 1;
+    }
+}
+
 $template->param(
 
-    units => \@units,
+    proflist     => \@proflist,
+    units        => \@units,
+    fonts        => \@fonts,
 
     tmpl_id      => $tmpl->{'tmpl_id'},
     tmpl_code    => $tmpl->{'tmpl_code'},
@@ -70,11 +118,6 @@ $template->param(
     rowgap       => $tmpl->{'rowgap'},
     fontsize     => $tmpl->{'fontsize'},
     active       => $tmpl->{'active'},
-
-    intranetcolorstylesheet =>
-      C4::Context->preference("intranetcolorstylesheet"),
-    intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-    IntranetNav        => C4::Context->preference("IntranetNav"),
 );
 
 output_html_with_http_headers $query, $cookie, $template->output;