merging katipo changes...
[koha.git] / opac / opac-main.pl
1 #!/usr/bin/perl
2 use strict;
3 require Exporter;
4 use CGI;
5 use HTML::Template;
6
7 use C4::Context;
8 use C4::Auth;       # get_template_and_user
9 use C4::Interface::CGI::Output;
10 use C4::BookShelves;
11 use C4::Koha;
12 use C4::Members;
13
14 my $input = new CGI;
15 my $kohaVersion = C4::Context->config("kohaversion");
16 my $dbh = C4::Context->dbh;
17 my $query="Select itemtype,description from itemtypes order by description";
18 my $sth=$dbh->prepare($query);
19 $sth->execute;
20 my  @itemtypeloop;
21 my %itemtypes;
22 while (my ($value,$lib) = $sth->fetchrow_array) {
23         my %row =(      value => $value,
24                                 description => $lib,
25                         );
26         push @itemtypeloop, \%row;
27 }
28 $sth->finish;
29
30 my @branches;
31 my @select_branch;
32 my %select_branches;
33 my $branches = getallbranches();
34 my @branchloop;
35 foreach my $thisbranch (keys %$branches) {
36         my $selected = 1 if (C4::Context->userenv && ($thisbranch eq C4::Context->userenv->{branch}));
37         my %row =(value => $thisbranch,
38                                 selected => $selected,
39                                 branchname => $branches->{$thisbranch}->{'branchname'},
40                         );
41         push @branchloop, \%row;
42 }
43
44 my ($template, $borrowernumber, $cookie)
45     = get_template_and_user({template_name => "opac-main.tmpl",
46                              type => "opac",
47                              query => $input,
48                              authnotrequired => 1,
49                              flagsrequired => {borrow => 1},
50                          });
51 my $borrower = getmember('',$borrowernumber);
52 my @options;
53 my $counter=0;
54 foreach my $language (getalllanguages()) {
55         next if $language eq 'images';
56         next if $language eq 'CVS';
57         next if $language=~ /png$/;
58         next if $language=~ /css$/;
59         my $selected='0';
60 #                            next if $currently_selected_languages->{$language};
61         push @options, { language => $language, counter => $counter };
62         $counter++;
63 }
64 my $languages_count = @options;
65
66 if($languages_count > 1){
67                 $template->param(languages => \@options);
68 }
69
70 my $branchinfo = getbranchinfo();
71 my @loop_data =();
72 foreach my $branch (@$branchinfo) {
73         my %row =();
74         $row{'branch_name'} = $branch->{'branchname'};
75         $row{'branch_hours'} = $branch->{'branchhours'};
76         $row{'branch_hours'} =~ s^\n^<br />^g;
77         push (@loop_data, \%row);
78     }
79
80 sub getbranchinfo {
81         my $dbh = C4::Context->dbh;
82         my $sth;
83         $sth = $dbh->prepare("Select * from branches order by branchcode");
84         $sth->execute();
85     
86         my @results;
87         while(my $data = $sth->fetchrow_hashref) {
88                     push(@results, $data);
89                 }
90         $sth->finish;
91         return \@results;
92 }
93
94
95 $template->param(CGIitemtype => $CGIitemtype,
96                                 suggestion => C4::Context->preference("suggestion"),
97                                 virtualshelves => C4::Context->preference("virtualshelves"),
98                                 textmessaging => $borrower->{textmessaging},
99                                 opaclargeimage => C4::Context->preference("opaclargeimage"),
100                                 LibraryName => C4::Context->preference("LibraryName"),
101                                 OpacNav => C4::Context->preference("OpacNav"),
102                                 opaccredits => C4::Context->preference("opaccredits"),
103                                 opacreadinghistory => C4::Context->preference("opacreadinghistory"),
104                                 opacsmallimage => C4::Context->preference("opacsmallimage"),
105                                 opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"),
106                                 opaccolorstylesheet => C4::Context->preference("opaccolorstylesheet"),
107                                 opaclanguagesdisplay => C4::Context->preference("opaclanguagesdisplay"),
108                                 branches => \@loop_data,
109 );
110
111 $template->param('Disable_Dictionary'=>C4::Context->preference("Disable_Dictionary")) if (C4::Context->preference("Disable_Dictionary"));
112
113 output_html_with_http_headers $input, $cookie, $template->output;