Line # Revision Author
1 196 ahitrov <& "/contenido/components/header.msn" &>
2 <& "/contenido/components/naviline.msn", sect_id => $owner->id &>
3
4 <table width="100%" cellspacing="0" cellpadding="0" border="0">
5 <tr valign="top">
6 <td width="35%">
7
8 <& /contenido/users/components/find_user.msn,
9 search => $search, search_by => $search_by,
10 url=>'sections.html' &>
11
12 <& "/contenido/users/components/subsection.msn", section => $owner &>
13 <& "/contenido/components/class_filter.msn", class=> $class, section => $owner &>
14
15 % if (( $owner->id ) && ($owner->id > 0) && $owner->id != 1 )
16 % {
17 <& "/contenido/components/section_info.msn", section => $owner &>
18 % }
19
20 </td>
21 <td width="2%">&nbsp;</td>
22 <td width="65%">
23
24 % if($owner->id) {
25
26 <fieldset>
27 <legend>Документы\
28 % if ($class) {
29 класса <% $class %>\
30 % if ($use_section) {
31 c учетом текущей секции\
32 % }
33 % } else {
34 в разделе\
35 % }
36 % if ($total > 0) {
37 (всего: <% $total %>, показано с <% $first + 1 %> по <% ($first + $n > $total) ? $total : $first + $n %>)
38 % }
39 </legend>
40
41 % if ($total or defined($alpha) or defined($search) ) {
42 % if ($section_access == 2) {
43 <& "/contenido/components/new_objects_form.msn", proto => 'documents',
44 sect_id => $owner->id,
45 default => ($owner->default_document_class ? $owner->default_document_class : $class) &>
46 % }
47 <div style="font-size:75%; font-family:Arial;">
48 <table border="0" cellspacing="0" cellpadding="2" width="100%" style="margin:4px 0 0; border:1px solid gray;">
49 <tr bgcolor="#e0e0e0"><th colspan="4">Поиск по букве:&nbsp;&nbsp;[<a href="?id=<% $id %>" style="font-weight:normal;">сброс фильтра</a>]</th></tr>
50 <tr><td style="font-size:75%; font-family:Arial; padding:2px 4px;">
51 <& /inc/alpha.msn, alpha=>$alpha, params=>\%ARGS, &>
52 </td></tr></table>
53 % ## Форма поиска. Работает при включенном фильтре класса
54 % ## и описанной для класса функции search_fields
55 % ########################################################
56 % if ( $filter{class} ) {
57 % my $document = $filter{class}->new ($keeper);
58 % my @fields = $document->search_fields;
59 % if ( @fields ) {
60 % my @props = $document->required_properties;
61 <form action="sections.html">
62 <table border="0" cellspacing="0" cellpadding="2" width="100%" style="margin:4px 0; border:1px solid gray;">
63 <tr bgcolor="#e0e0e0"><th colspan="4">Поиск по полю:&nbsp;&nbsp;[<a href="?id=<% $id %>" style="font-weight:normal;">сброс фильтра</a>]</th></tr><tr>
64 <td width="1%" nowrap style="padding:2px 0 2px 4px;"><select name="search_by">
65 % foreach my $field ( @fields ) {
66 % my ($prop) = grep { $_->{'attr'} eq $field } @props;
67 % my $selected = $field eq $search_by ? ' selected' : '';
68 <option value="<% $field %>"<% $selected %>><% ref $prop ? $prop->{'rusname'} : $field %>
69 % }
70 </td><td width="0">:</td>
71 <td width="98%"><input type="text" name="search" value="<% $search %>" style="width:100%"></td>
72 <td width="1%" style="padding:2px 4px 2px 0;"><input type="submit" value=" &raquo; " style="border:1px solid gray;"></td>
73 </tr></table>
74 % if ( $id ) {
75 <input type="hidden" name="id" value="<% $id %>">
76 % }
77 % if ( $class ) {
78 <input type="hidden" name="class" value="<% $class %>">
79 % }
80 % if ( $use_section ) {
81 <input type="hidden" name="use_section" value="<% $use_section %>">
82 % }
83 </form>
84 % }
85 % }
86
87 <div style="height:5px"><spacer type="block" height="5"></div>
88 <& /inc/pages_.msn, p=>$p, n=>$n, total=>$total, href=>'sections.html', params=>\%ARGS, &>
89 </div>
90
91 <& /contenido/components/section_browse.msn, documents => \@documents, columns => \@columns, section => $owner, filter => \%filter_params, %ARGS &>
92
93 <div style="font-size:75%; font-family:Arial;">
94 <& /inc/pages_.msn, p=>$p, n=>$n, total=>$total, href=>'sections.html', params=>\%ARGS, &>
95 <div style="height:5px"><spacer type="block" height="5"></div>
96 </div>
97
98 % } else {
99 <h4 align="center"><i>---- Нет документов -----</i></h4>
100 % }
101 %
102 % if ($section_access == 2) {
103 <& "/contenido/components/new_objects_form.msn", proto => 'documents',
104 sect_id => $owner->id,
105 default => ($owner->default_document_class ? $owner->default_document_class : $class) &>
106 % }
107
108 </fieldset>
109 </td>
110 </tr>
111 </table>
112
113 % }
114
115 </body>
116 </html>
117 <%args>
118
119 $id => 1
120 $p => 1
121 $class => undef
122 $use_section => undef
123 $alpha => undef
124 $alpha_search => undef
125 $search_by => undef
126 $search => undef
127 $update => undef
128 $delete => undef
129
130 </%args>
131 <%init>
132
133 $id = 0 if $id =~ /\D/;
134 my $owner;
135
136 # Операции...
137 if ($id && ($id > 0))
138 {
139 $owner = $keeper->get_section_by_id($id);
140 }
141 if (! ref($owner))
142 {
143 return undef;
144 }
145
146 $class = $state->{users}->profile_document_class;
147 $use_section = 1 if $id != 1;
148
149 my %filter_params;
150 $filter_params{use_section} = $use_section if $use_section;
151 $filter_params{class} = $class if $class;
152 $filter_params{alpha} = $alpha if $alpha;
153 $filter_params{alpha_search} = $alpha_search if $alpha_search;
154 $filter_params{search_by} = $search_by if $search_by;
155 $filter_params{search} = $search if $search;
156 $filter_params{p} = $p if $p > 1;
157 $filter_params{s} = $id if $id && $id != 1;
158
159 # Фильтры работают в любом случае...
160 my $filter = $m->comp('/contenido/components/context.msn', name => 'filter');
161 my $profile = $m->comp('/contenido/components/context.msn', name => 'profile');
162
163 unless (defined $request->{section_accesses}->{$id})
164 {
165 $request->{section_accesses}->{$id} = $user->get_section_access($id);
166 }
167 my $section_access = $request->{section_accesses}->{$id};
168
169 my (@documents, $total);
170
171 my $s = $owner->id;
172 my $sorted = $owner->_sorted();
173 $s .= ",$filter" if ($filter > 0);
174
175 if ($update) {
176 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
177 my %updated;
178 while ( my ($field, $value) = each %ARGS ) {
179 if ( $field =~ /^update_(\d+)_(\w+)$/ ) {
180 my $oid = $1;
181 my $attr = $2;
182 $updated{$oid}{$attr} = $value;
183 }
184 }
185 my %classes = map { $_->{class} => 1 } values %updated;
186 foreach my $update_class ( keys %classes ) {
187 my @ids;
188 while ( my ($oid, $attr) = each %updated) {
189 push @ids, $oid if $attr->{class} eq $update_class;
190 }
191 my @objects = $keeper->get_documents (
192 id => \@ids,
193 class => $update_class
194 ) if @ids;
195 foreach my $object ( @objects ) {
196 my $document_access = $user->section_accesses($user, $object->section);
197 next unless $document_access == 2;
198 my $fields = $updated{$object->id};
199 my @props = grep { exists $_->{inline} && $_->{inline} } $object->structure;
200 if ( ref $fields eq 'HASH' ) {
201 foreach my $prop ( @props ) {
202 my $attr = $prop->{attr};
203 my $value = ref $fields && exists $fields->{$attr} ? $fields->{$attr} : undef;
204 if ( $prop->{db_type} eq 'float' ) {
205 for ( $value ) {
206 s/\,/\./;
207 s/^\s+//;
208 s/\s+$//;
209 }
210 }
211 if ( $prop->{type} eq 'checkbox' ) {
212 $value = $value ? 1 : undef;
213 }
214
215 $object->$attr($value);
216 }
217 $object->store;
218 }
219 }
220 }
221 $m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : ''));
222 }
223 if ( $delete ) {
224 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
225 my %deleted;
226 while ( my ($field, $value) = each %ARGS ) {
227 if ( $field =~ /^delete_(\d+)_(\w+)$/ ) {
228 my $oid = $1;
229 my $attr = $2;
230 $deleted{$oid}{$attr} = $value;
231 }
232 }
233 my %classes = map { $_->{class} => 1 } values %deleted;
234 foreach my $delete_class ( keys %classes ) {
235 my @ids;
236 while ( my ($oid, $attr) = each %deleted) {
237 push @ids, $oid if exists $attr->{id} && $attr->{id} && ($attr->{class} eq $delete_class);
238 }
239 my @objects = $keeper->get_documents (
240 id => \@ids,
241 class => $delete_class
242 ) if @ids;
243 foreach my $object ( @objects ) {
244 my $document_access = $user->section_accesses($user, $object->section);
245 next unless $document_access == 2;
246 $object->delete;
247 }
248 }
249 $m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : ''));
250 }
251
252 my %filter=();
253 my %order = (not $class and $owner->order_by) ? (order_by => $owner->order_by) : (order => ['date','direct']);
254 if (defined $alpha and $alpha ne '') {
255 $filter{ilike}=1;
256 $filter{ $alpha_search || 'name' }="$alpha%";
257 $order{order}=['name','reverse'];
258 delete $order{order_by};
259 }
260
261 $filter{class} = $owner->default_document_class if $owner->default_document_class;
262 $filter{class} = $class if ($class);
263 $filter{s}=$s unless ($class && !$use_section);
264 if ( $search_by && defined $search ) {
265 my $doc_class = $class || $owner->default_document_class;
266 if ( $doc_class ) {
267 my @props = $doc_class->new( $keeper )->structure();
268 my ($prop) = grep { $_->{attr} eq $search_by } @props if @props;
269 if ( ref $prop && $prop->{type} eq 'integer' ) {
270 $filter{$search_by} = int($search);
271 } else {
272 $filter{$search_by}='%'.$search.'%';
273 $filter{ilike} = 1;
274 }
275 } else {
276 $filter{$search_by}='%'.$search.'%';
277 $filter{ilike} = 1;
278 }
279 }
280
281 # Дополнительные фильтры раздела
282 if ($owner->filters) {
283 no strict 'vars';
284 my $filters = eval($owner->filters);
285 if ($@) {
286 warn "Bad filter: " . $owner->filters . " in section " . $owner->id;
287 } elsif (ref $filters eq 'HASH') {
288 map { $filter{$_} = $filters->{$_} } keys %$filters;
289 }
290 }
291
292 $total = $keeper->get_documents(%filter, count=>1);
293
294 my $n = 40;
295 my $first = $n * ($p - 1);
296 ($first,$p)=(0,0) if ($first>$total);
297
298 if ($class && !$use_section) {
299 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
300 } elsif ($sorted) {
301 @documents = $keeper->get_sorted_documents(%filter, limit=>$n, offset=>$first);
302 } else {
303 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
304 }
305
306 # набор колонок таблицы документов...
307 my @columns = $sorted ? ({attr => '_sort_', name => 'N'}) : ();
308
309 # пытаемся найти колонки, которые документ сам пожелал показать (required_properties -> column)...
310 if ($filter{class} or @documents and $documents[0]) {
311 push @columns,
312 sort {$a->{column} <=> $b->{column}}
313 grep {$_->{column}} ($filter{class} ? $filter{class}->new($keeper)->structure : $documents[0]->structure);
314 }
315
316 # стандартная жопка таблицы...
317 @columns = (@columns,
318 {attr => '_act_', rusname => 'Действия'},
319 );
320 </%init>