Line # Revision Author
1 8 ahitrov@rambler.ru %# vim:syn=mason:
2 % index_tree( $sect->{$root}, 0, \$line, $level, $mode, $profile, $width_limit, $root );
3 <%once>
4
5 use Encode;
6
7 </%once>
8 <%args>
9
10 $root => 1
11 $level => 3
12 $mode => 1
13 $width_limit => undef
14 $avail_classes => undef
15
16 </%args>
17 <%init>
18 my $profile = $m->comp('/contenido/components/context.msn', name => 'profile');
19
20 sub index_tree
21 {
22 my ($sect, $offset, $line_ref, $count_offset, $viewmode, $profile, $width_limit, $root) = @_;
23 my $section_access = $user->section_accesses($user, $sect->{id});
24
25 my $spacer = '';
26 for(my $c=1; $c<$offset; $c++)
27 {
28 $spacer = $spacer.(($c == $offset-1) ? '&nbsp;&nbsp;&raquo;&nbsp;&nbsp;' : '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
29 }
30 if( ref $sect && $sect->id && ($sect->id != 1) && ($offset != 0) && $section_access > 0)
31 {
32 $$line_ref++;
33
34 my $href = 'sections.html?id='.$sect->id;
35
36 my $sname = decode("utf-8", $sect->name());
37 if ( defined $width_limit && $offset + length($sname) > $width_limit ) {
38 $sname = substr($sname, 0, $width_limit - $offset);
39 $sname .= '&nbsp;...';
40 }
41 $sname = encode("utf-8", $sname);
42 my $statstyle = $sect->contenido_status_style ? ' style="' . $sect->contenido_status_style . '"' : '';
43 my @properties = $sect->structure();
44 my ($statprop) = grep { $_->{attr} eq 'status' } @properties;
45 my ($statcase) = grep { $_->[0] == $sect->status } @{$statprop->{cases}} if exists $statprop->{cases} && ref $statprop->{cases} eq 'ARRAY';
46 my $statname = $statcase->[1] if ref $statcase;
47 my $html_sect = '<span'.($statstyle).(!$sect->status ? ' class="hiddensect"' : '').'>'.($section_access ? '<a href="'.$href.'"'.$statstyle.'>' : '').$sname.($section_access ? '</a>' : '') . '&nbsp;'.($sect->status != 1 && $statname ? '&nbsp;<span style="font-size:11px;">('.$statname.')</span>' : '').'</span>';
48 my $style = ($offset == 1) ? ($viewmode ? ' style="font-size:110%;"':' style="font-size:95%;"') : '';
49
50 $m->out(<<EOT);
51 <tr>
52 <td align="right">&nbsp;${$line_ref}&nbsp;<a href="section.html?id=$sect->{id}&move=up&ret=$root"><img src="/contenido/i/ico-up-9x10.gif" border=0 alt="Переместить секцию на шаг вверх"></a>&nbsp;<a href="section.html?id=$sect->{id}&move=down&ret=$root"><img src="/contenido/i/ico-down-9x10.gif" border=0 alt="Переместить секцию на шаг вниз"></a></td>
53 <td><table cellpadding="0" cellspacing="0" border="0">
54 <tr valign="top">
55 <td width="10">&nbsp;</td>
56 <td>$spacer</td>
57 <td nowrap $style>$html_sect</td>
58 </tr>
59 </table>
60 </td>
61 EOT
62
63 if ($viewmode)
64 {
65 my $fhref = '/contenido/?set_context=filter-'.$sect->id();
66 my $new_doc_class = $sect->default_document_class;
67 $m->out(qq^\n<td align="center" nowrap><a href="$fhref">уст.фильтр</a>^);
68 $m->out(qq^&nbsp;&nbsp;&nbsp;<a href="document.html?sect_id=$sect->{id}&class=$new_doc_class">доб.докум</a>^) if $section_access == 2 and $new_doc_class;
69 $m->out("</td>");
70 }
71
72 $m->out('</tr>');
73 }
74
75 my $childs = $sect->{children} || [];
76 if( ref($childs) && @$childs && $offset < $count_offset )
77 {
78 $offset++;
79 foreach my $child (@$childs)
80 {
81 next if (! $request->{cCLASSES}->{$child->class()});
82 index_tree( $child, $offset, $line_ref, $count_offset, $viewmode, $profile, $width_limit, $root );
83 }
84 $offset--;
85 }
86 }
87
88 $request->{cCLASSES} = {};
89 my @avail_classes;
90 if ( ref $avail_classes eq 'ARRAY' && @$avail_classes ) {
91 map { $request->{cCLASSES}->{$_} = 1 } @$avail_classes;
92 @avail_classes = @$avail_classes;
93 } elsif (ref($request->{tab}->{sections})) {
94 map { $request->{cCLASSES}->{$_} = 1 } (@{ $request->{tab}->{sections} });
95 return undef if (scalar(keys(%{ $request->{cCLASSES} })) == 0);
96 @avail_classes = keys( %{ $request->{cCLASSES} } );
97 }
98 push @avail_classes, 'Contenido::Section' unless exists $request->{cCLASSES}{'Contenido::Section'};
99 my $sect = $keeper->get_section_tree(root=>$root, class => \@avail_classes);
100 return undef unless ref $sect && exists $sect->{$root};
101
102 $user->get_accesses();
103
104 my $line = 0;
105
106 </%init>