6 use Apache::Session::Postgres;
18 our $last_modified = '$Date: 2011-11-19 11:08:01 $';
23 $dbh = DBI->connect("dbi:Pg:dbname=$itkaclconfig::db_name;host=$itkaclconfig::db_host",
24 $itkaclconfig::db_user, $itkaclconfig::db_pass)
25 or die "Couldn't connect to database";
26 $dbh->{pg_enable_utf8} = 1;
27 $last_modified = '$Date: 2011-11-19 11:08:01 $';
34 # Find the cookie, if any
35 my $session_id = $cgi->cookie('itkaclsession');
36 tie %session, 'Apache::Session::Postgres', $session_id, {
37 DataSource => "dbi:Pg:dbname=$itkaclconfig::sessiondb_name;host=$itkaclconfig::sessiondb_host",
38 UserName => $itkaclconfig::sessiondb_user,
39 Password => $itkaclconfig::sessiondb_pass,
43 # Update with open/close
44 my $open = $cgi->param('open');
45 my $close = $cgi->param('close');
48 } elsif (defined($close)) {
49 undef $session{$close};
52 my $cookie = $cgi->cookie(-name=>'itkaclsession',
53 -value=>$session{_session_id},
56 binmode STDOUT, ":utf8";
57 print $cgi->header(-type=>'application/xhtml+xml; charset=utf-8', cookie=>$cookie, -expires=>'now');
59 open HEADER, "<", $itkaclconfig::header
60 or die "Couldn't open $itkaclconfig::header: $!";
62 # Find out if we're using SSO.
64 if (defined($ENV{'AUTH_TYPE'}) && $ENV{'AUTH_TYPE'} eq 'Negotiate') {
65 $sso = '<img src="https://itk.samfundet.no/images/ssso-button.png" alt="Samfundet single sign-on" title="Samfundet single sign-on"/>';
70 delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)};
73 if (defined($itkaclconfig::quotescript)) {
74 # Hent inn quotes. Stygt, jodal! =)
75 $quote = `$itkaclconfig::quotescript`;
76 $quote = Encode::decode_utf8($quote);
80 s/\%QUOTES\%/$quote/ if defined($quote);
83 s/\%TITLE\%/ITKACL-tre/;
84 s/"http:\/\/([^"]*\.(css|png))"/"https:\/\/$1"/;
95 open FOOTER, "<", $itkaclconfig::footer
96 or die "Couldn't open $itkaclconfig::footer: $!";
98 # Strip RCS stuff from $::last_modified
99 (my $lm = $last_modified) =~ s/^\$[D]ate: (.*) \$$/$1/;
102 s/\%LAST_MODIFIED\%/$lm/;
110 my ($fulltree, $boldelem) = @_;
112 print " <div class=\"tree\">\n";
114 print " <div class=\"tree floatingtree\">\n";
117 print " <p><img src=\"/img/base-folder.png\" alt=\"\" width=\"21\" height=\"18\" />Samfundet</p>\n";
119 print_tree_element($dbh, undef, 0, [], $fulltree, $boldelem);
124 sub print_tree_element {
125 my ($dbh, $curr_obj, $level, $vbars, $fulltree, $boldelem) = @_;
128 if (defined($curr_obj)) {
129 $refs = $dbh->selectall_arrayref('SELECT id,name,description FROM objects WHERE parent=? ORDER BY name', undef, $curr_obj);
131 $refs = $dbh->selectall_arrayref('SELECT id,name,description FROM objects WHERE parent IS NULL ORDER BY name');
135 my $count = (scalar @{$refs}) - 1;
136 for my $ref (@{$refs}) {
139 my @vbarscopy = @{$vbars};
144 $msb = "-moresiblings";
150 # Stuff to the left of folder
151 for my $i (1..$level) {
152 if ($vbars->[$i - 1]) {
153 print '<img src="/img/verticalbar.png" alt="|" width="16" height="18" />';
155 print '<img src="/img/whitespace.png" alt=" " width="16" height="18" />';
160 my $countref = $dbh->selectrow_hashref('SELECT COUNT(*) AS num FROM objects WHERE parent=?', undef, $ref->[0]);
161 if ($countref->{'num'} == 0) {
163 print "<img src=\"/img/folder-nochildren.png\" alt=\"\" width=\"37\" height=\"18\" />";
165 print "<img src=\"/img/folder-nochildren-moresiblings.png\" alt=\"|\" width=\"37\" height=\"18\" />";
168 my $url = $cgi->url(-absolute=>1) . "?";
170 for my $p ($cgi->param()) {
171 next if ($p eq 'open');
172 next if ($p eq 'close');
173 push @params, "$p=" . $cgi->param($p);
175 if (scalar @params > 0) {
176 $url .= join('&', @params) . "&";
179 if (defined($session{$ref->[0]})) {
180 print "<a href=\"${url}close=$ref->[0]\"><img src=\"/img/folder-open$msb.png\" alt=\"-\" width=\"37\" height=\"18\" /></a>";
182 print "<a href=\"${url}open=$ref->[0]\"><img src=\"/img/folder-closed$msb.png\" alt=\"+\" width=\"37\" height=\"18\" /></a>";
186 if (defined($boldelem) && $boldelem == $ref->[0]) {
190 my $e_entity = HTML::Entities::encode_entities($ref->[1]);
191 my $e_description = HTML::Entities::encode_entities($ref->[2]);
194 print "<a href=\"/view.pl?entry=$ref->[0]\">$e_entity: $e_description</a>";
196 print "<a href=\"/view.pl?entry=$ref->[0]\" title=\"$e_description\">$e_entity</a>";
199 if (defined($boldelem) && $boldelem == $ref->[0]) {
204 if ($countref->{'num'} > 0 && defined($session{$ref->[0]})) {
205 print_tree_element($dbh, $ref->[0], $level + 1, \@vbarscopy, $fulltree, $boldelem);