+sub availablethemes {
+ my ($htdocs, $tmpl, $interface, $lang) = @_;
+
+ # Get theme
+ my @themes;
+ my $theme_syspref = ($interface eq 'intranet') ? 'template' : 'opacthemes';
+ my $fallback_syspref = ($interface eq 'intranet') ? 'template' : 'OPACFallback';
+ # Yeah, hardcoded, last resort if the DB is not populated
+ my $hardcoded_theme = ($interface eq 'intranet') ? 'prog' : 'bootstrap';
+
+ # Configured theme is the first one
+ push @themes, C4::Context->preference( $theme_syspref )
+ if C4::Context->preference( $theme_syspref );
+ # Configured fallback next
+ push @themes, C4::Context->preference( $fallback_syspref )
+ if C4::Context->preference( $fallback_syspref );
+ # The hardcoded fallback theme is the last one
+ push @themes, $hardcoded_theme;
+
+ # Try to find first theme for the selected theme/lang, then for fallback/lang
+ my $where = $tmpl =~ /xsl$/ ? 'xslt' : 'modules';