Line # Revision Author
1 842 ahitrov <!DOCTYPE html>
2 8 ahitrov@rambler.ru <& "/contenido/components/header.msn" &>
3 <& "/contenido/components/naviline.msn", sect_id => $owner->id &>
4
5 17 ahitrov@rambler.ru <script type="text/javascript">
6 <!--
7 function set_create_button( oSelect, sBtnID ) {
8 if ( oSelect.value == '' ) {
9 $('#'+sBtnID).attr('disabled','disabled');
10 } else {
11 $('#'+sBtnID).removeAttr('disabled');
12 }
13 }
14 //-->
15 </script>
16
17 8 ahitrov@rambler.ru <table width="100%" cellspacing="0" cellpadding="0" border="0">
18 <tr valign="top">
19 607 ahitrov <td id="column-side">
20 8 ahitrov@rambler.ru
21 <& "/contenido/components/subsection.msn", section => $owner &>
22 <& "/contenido/components/class_filter.msn", class=> $class, section => $owner &>
23
24 % if (( $owner->id ) && ($owner->id > 0) )
25 % {
26 <& "/contenido/components/section_info.msn", section => $owner &>
27 % }
28
29 % my @LEFT = $m->comp('components/tasks.msn');
30 % my %LEFTh = map { $_->{attr} => $_ } (@LEFT);
31 % if (ref($request->{tab}->{lefts}))
32 % {
33 % for my $left (@{ $request->{tab}->{lefts} })
34 % {
35 % next if (! exists($LEFTh{$left}));
36 <& '/contenido/components/'.$LEFTh{$left}->{component}, %ARGS &>
37 % }
38 % }
39
40 <!-- Примечания -->
41 <fieldset>
42 <legend>Примечания</legend>
43 <table width="100%" cellspacing="5" cellpadding="0" class="tform">
44
45 <tr>
46 <th valign=top>1)</th>
47 <td width="100%">
48 Дата и время документа - поле, которое Вы можете редактировать.<br><br>
49 Кроме этого у каждого документа существует еще две временные отметки - дата создания (ctime) и дата модификации (mtime).
50 Это служебные поля и Вы не можете их изменять (они доступны только для чтения).
51 </td>
52 </tr>
53
54 </table>
55 </fieldset>
56
57 </td>
58 607 ahitrov <td width="2%"><a href="javascript:void()" class="width-toggler"><img src="/contenido/i/icons/left-right.png" width="30"></a></td>
59 <td id="column-content">
60 8 ahitrov@rambler.ru % if($owner->id) {
61
62 <fieldset>
63 <legend>Документы\
64 % if ($class) {
65 класса <% $class %>\
66 % if ($use_section) {
67 c учетом текущей секции\
68 % }
69 % } else {
70 в разделе\
71 % }
72 118 ahitrov % if (!$owner->no_count && $total > 0) {
73 624 ahitrov (всего: <% $total %>, показано с <% $first + 1 %> по <% $sorted ? $total : ($first + $n > $total) ? $total : $first + $n %>)
74 118 ahitrov % } elsif ( $owner->no_count ) {
75 (<span style="color:yellow">без пересчета</span>, показано с <% $first + 1 %> по <% $first + scalar @documents %>)
76 8 ahitrov@rambler.ru % }
77 </legend>
78
79 118 ahitrov % if ($total || scalar @documents || defined($alpha) || defined($search) ) {
80 616 ahitrov <table border="0" cellspacing="0" cellpadding="2" width="100%">
81 <tr>
82 8 ahitrov@rambler.ru % if ($section_access == 2) {
83 616 ahitrov <td width="99%">
84 8 ahitrov@rambler.ru <& "/contenido/components/new_objects_form.msn", proto => 'documents',
85 616 ahitrov sect_id => $owner->id, section => $owner,
86 default => ($owner->default_document_class ? $owner->default_document_class : undef) &>
87 </td>
88 8 ahitrov@rambler.ru % }
89 616 ahitrov <td width="1%">
90 <& "/contenido/components/section_page_size.msn", section => $owner &>
91 </td>
92 </tr>
93 </table>
94 117 ahitrov <div style="font-size:12px; font-family:Arial;">
95 8 ahitrov@rambler.ru <table border="0" cellspacing="0" cellpadding="2" width="100%" style="margin:4px 0 0; border:1px solid gray;">
96 <tr bgcolor="#e0e0e0"><th colspan="4">Поиск по букве:&nbsp;&nbsp;[<a href="?id=<% $id %>" style="font-weight:normal;">сброс фильтра</a>]</th></tr>
97 117 ahitrov <tr><td style="font-size:12px; font-family:Arial; padding:2px 4px;">
98 8 ahitrov@rambler.ru <& /inc/alpha.msn, alpha=>$alpha, params=>\%ARGS, &>
99 </td></tr></table>
100 % ## Форма поиска. Работает при включенном фильтре класса
101 % ## и описанной для класса функции search_fields
102 % ########################################################
103 450 ahitrov % if ( $filter{class} || $filter{table} ) {
104 459 ahitrov % my ($document) = $filter{class} ? ($filter{class}->new( $keeper )) : map { $_->new( $keeper ) } grep { $_->new( $keeper )->class_table eq $owner->default_table_class } @{ $user->get_available_classes };
105 8 ahitrov@rambler.ru % my @fields = $document->search_fields;
106 % if ( @fields ) {
107 % my @props = $document->required_properties;
108 <form action="sections.html">
109 <table border="0" cellspacing="0" cellpadding="2" width="100%" style="margin:4px 0; border:1px solid gray;">
110 <tr bgcolor="#e0e0e0"><th colspan="4">Поиск по полю:&nbsp;&nbsp;[<a href="?id=<% $id %>" style="font-weight:normal;">сброс фильтра</a>]</th></tr><tr>
111 <td width="1%" nowrap style="padding:2px 0 2px 4px;"><select name="search_by">
112 % foreach my $field ( @fields ) {
113 % my ($prop) = grep { $_->{'attr'} eq $field } @props;
114 % my $selected = $field eq $search_by ? ' selected' : '';
115 <option value="<% $field %>"<% $selected %>><% ref $prop ? $prop->{'shortname'} || $prop->{'rusname'} : $field %>
116 % }
117 </td><td width="0">:</td>
118 <td width="98%"><input type="text" name="search" value="<% $search %>" style="width:100%"></td>
119 <td width="1%" style="padding:2px 4px 2px 0;"><input type="submit" value=" &raquo; " style="border:1px solid gray;"></td>
120 </tr></table>
121 % if ( $id ) {
122 <input type="hidden" name="id" value="<% $id %>">
123 % }
124 % if ( $class ) {
125 <input type="hidden" name="class" value="<% $class %>">
126 % }
127 % if ( $use_section ) {
128 <input type="hidden" name="use_section" value="<% $use_section %>">
129 % }
130 </form>
131 % }
132 % }
133
134 <div style="height:5px"><spacer type="block" height="5"></div>
135 118 ahitrov % if ( $owner->no_count ) {
136 <& /inc/pages_nocount.msn, p=>$p, n=>$n, found=> scalar @documents, href=>'sections.html', params=>\%ARGS, size => 15 &>
137 624 ahitrov % } elsif ( $sorted ) {
138 118 ahitrov % } else {
139 8 ahitrov@rambler.ru <& /inc/pages_.msn, p=>$p, n=>$n, total=>$total, href=>'sections.html', params=>\%ARGS, &>
140 118 ahitrov % }
141 8 ahitrov@rambler.ru </div>
142
143 <& /contenido/components/section_browse.msn, documents => \@documents, columns => \@columns, section => $owner, filter => \%filter_params, %ARGS &>
144
145 117 ahitrov <div style="font-size:12px; font-family:Arial;">
146 118 ahitrov % if ( $owner->no_count ) {
147 <& /inc/pages_nocount.msn, p=>$p, n=>$n, found=> scalar @documents, href=>'sections.html', params=>\%ARGS, size => 15 &>
148 624 ahitrov % } elsif ( $sorted ) {
149 118 ahitrov % } else {
150 8 ahitrov@rambler.ru <& /inc/pages_.msn, p=>$p, n=>$n, total=>$total, href=>'sections.html', params=>\%ARGS, &>
151 118 ahitrov % }
152 8 ahitrov@rambler.ru <div style="height:5px"><spacer type="block" height="5"></div>
153 </div>
154
155 % } else {
156 <h4 align="center"><i>---- Нет документов -----</i></h4>
157 % }
158 %
159 % if ($section_access == 2) {
160 <& "/contenido/components/new_objects_form.msn", proto => 'documents',
161 sect_id => $owner->id,
162 default => ($owner->default_document_class ? $owner->default_document_class : undef) &>
163 % }
164
165 </fieldset>
166 </td>
167 </tr>
168 </table>
169
170 % }
171
172 </body>
173 </html>
174 607 ahitrov <%once>
175
176 my $cookie_name = 'content_fullwidth';
177
178 </%once>
179 8 ahitrov@rambler.ru <%args>
180
181 $id => undef
182 $p => 1
183 $class => undef
184 $use_section => undef
185 $alpha => undef
186 $alpha_search => undef
187 $search_by => undef
188 $search => undef
189 $update => undef
190 $delete => undef
191
192 </%args>
193 <%init>
194
195 $id = 0 if $id =~ /\D/;
196 607 ahitrov my $content_fullwidth = $m->comp('/contenido/components/cookies.msn', name => $cookie_name);
197
198 8 ahitrov@rambler.ru my $owner;
199
200 # Операции...
201 if ($id && ($id > 0))
202 {
203 $owner = $keeper->get_section_by_id($id);
204 }
205 if (! ref($owner))
206 {
207 return undef;
208 }
209
210 my %filter_params;
211 $filter_params{use_section} = $use_section if $use_section;
212 $filter_params{class} = $class if $class;
213 $filter_params{alpha} = $alpha if $alpha;
214 $filter_params{alpha_search} = $alpha_search if $alpha_search;
215 $filter_params{search_by} = $search_by if $search_by;
216 $filter_params{search} = $search if $search;
217 $filter_params{p} = $p if $p > 1;
218 $filter_params{s} = $id if $id;
219
220 16 ahitrov@rambler.ru # Фильтры работают в любом случае...
221 8 ahitrov@rambler.ru my $filter = $m->comp('/contenido/components/context.msn', name => 'filter');
222 my $profile = $m->comp('/contenido/components/context.msn', name => 'profile');
223
224 if ($update) {
225 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
226 my %updated;
227 while ( my ($field, $value) = each %ARGS ) {
228 if ( $field =~ /^update_(\d+)_(\w+)$/ ) {
229 my $oid = $1;
230 my $attr = $2;
231 $updated{$oid}{$attr} = $value;
232 }
233 }
234 my %classes = map { $_->{class} => 1 } values %updated;
235 foreach my $update_class ( keys %classes ) {
236 my @ids;
237 while ( my ($oid, $attr) = each %updated) {
238 push @ids, $oid if $attr->{class} eq $update_class;
239 }
240 my @objects = $keeper->get_documents (
241 id => \@ids,
242 class => $update_class
243 ) if @ids;
244 foreach my $object ( @objects ) {
245 my $document_access = $user->section_accesses($user, $object->section);
246 next unless $document_access == 2;
247 my $fields = $updated{$object->id};
248 my @props = grep { exists $_->{inline} && $_->{inline} } $object->structure;
249 if ( ref $fields eq 'HASH' ) {
250 foreach my $prop ( @props ) {
251 my $attr = $prop->{attr};
252 my $value = ref $fields && exists $fields->{$attr} ? $fields->{$attr} : undef;
253 395 ahitrov if ( $prop->{type} eq 'checkbox' ) {
254 $value = $value ? 1 : undef;
255 }
256 386 ahitrov if ( exists $prop->{db_type} ) {
257 if ( $prop->{db_type} eq 'float' ) {
258 for ( $value ) {
259 s/\,/\./;
260 s/^\s+//;
261 s/\s+$//;
262 }
263 if ( $value eq '' ) {
264 $value = undef;
265 }
266 } elsif ( $prop->{db_type} eq 'integer' || $prop->{db_type} eq 'smallint' ) {
267 $value =~ s/\D//sg if $value;
268 if ( $value eq '' ) {
269 $value = undef;
270 }
271 8 ahitrov@rambler.ru }
272 }
273
274 $object->$attr($value);
275 }
276 $object->store;
277 }
278 }
279 }
280 $m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : ''));
281 }
282 if ( $delete ) {
283 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
284 my %deleted;
285 while ( my ($field, $value) = each %ARGS ) {
286 if ( $field =~ /^delete_(\d+)_(\w+)$/ ) {
287 my $oid = $1;
288 my $attr = $2;
289 $deleted{$oid}{$attr} = $value;
290 }
291 }
292 my %classes = map { $_->{class} => 1 } values %deleted;
293 foreach my $delete_class ( keys %classes ) {
294 my @ids;
295 while ( my ($oid, $attr) = each %deleted) {
296 push @ids, $oid if exists $attr->{id} && $attr->{id} && ($attr->{class} eq $delete_class);
297 }
298 my @objects = $keeper->get_documents (
299 id => \@ids,
300 class => $delete_class
301 ) if @ids;
302 foreach my $object ( @objects ) {
303 my $document_access = $user->section_accesses($user, $object->section);
304 next unless $document_access == 2;
305 $object->delete;
306 }
307 }
308 $m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : ''));
309 }
310 386 ahitrov if ( $ARGS{move} || $ARGS{link} ) {
311 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
312 if ( exists $ARGS{tree} && $ARGS{tree} && $ARGS{tree} != $owner->id ) {
313 my %updated;
314 while ( my ($field, $value) = each %ARGS ) {
315 388 ahitrov if ( $field =~ /^delete_(\d+)_(\w+)$/ ) {
316 386 ahitrov my $oid = $1;
317 my $attr = $2;
318 $updated{$oid}{$attr} = $value;
319 }
320 }
321 522 ahitrov warn Dumper \%updated if $DEBUG;
322 386 ahitrov my %classes = map { $_->{class} => 1 } values %updated;
323 my $parent_new = $keeper->get_section_by_id( $ARGS{tree} );
324 my $document_access = $user->section_accesses($user, $parent_new->id);
325 if ( $document_access == 2 ) {
326 foreach my $update_class ( keys %classes ) {
327 my @ids;
328 while ( my ($oid, $attr) = each %updated) {
329 388 ahitrov push @ids, $oid if exists $attr->{id} && $attr->{id} && ($attr->{class} eq $update_class);
330 386 ahitrov }
331 my @objects = $keeper->get_documents (
332 id => \@ids,
333 class => $update_class
334 ) if @ids;
335 my ($prop) = grep { $_->{attr} eq 'sections' } $update_class->new( $keeper )->structure;
336 if ( ref $prop && exists $prop->{db_type} && exists $prop->{db_field} ) {
337 foreach my $object ( @objects ) {
338 if ( $prop->{db_type} eq 'integer[]' ) {
339 my @sections = grep { $_ != $parent_new->id } $object->sections;
340 if ( @sections && $sections[0] == $owner->id ) {
341 419 ahitrov if ( $ARGS{move} ) {
342 shift @sections;
343 unshift @sections, $parent_new->id;
344 } else {
345 push @sections, $parent_new->id;
346 }
347 } else {
348 if ( $ARGS{move} ) {
349 @sections = grep { $_ != $owner->id } @sections;
350 }
351 521 ahitrov push @sections, $parent_new->id;
352 386 ahitrov }
353 $object->sections( @sections );
354 } else {
355 $object->sections( $parent_new->id );
356 }
357 $object->store;
358 }
359 }
360 }
361 }
362 }
363 $m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : ''));
364 522 ahitrov } elsif ( $ARGS{unlink} ) {
365 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
366 my $document_access = $user->section_accesses($user, $owner->id);
367 my %updated;
368 while ( my ($field, $value) = each %ARGS ) {
369 if ( $field =~ /^delete_(\d+)_(\w+)$/ ) {
370 my $oid = $1;
371 my $attr = $2;
372 $updated{$oid}{$attr} = $value;
373 }
374 }
375 warn Dumper \%updated if $DEBUG;
376 my %classes = map { $_->{class} => 1 } values %updated;
377 if ( $document_access == 2 ) {
378 foreach my $update_class ( keys %classes ) {
379 my @ids;
380 while ( my ($oid, $attr) = each %updated) {
381 push @ids, $oid if exists $attr->{id} && $attr->{id} && ($attr->{class} eq $update_class);
382 }
383 my @objects = $keeper->get_documents (
384 id => \@ids,
385 class => $update_class
386 ) if @ids;
387 my ($prop) = grep { $_->{attr} eq 'sections' } $update_class->new( $keeper )->structure;
388 if ( ref $prop && exists $prop->{db_type} && exists $prop->{db_field} ) {
389 foreach my $object ( @objects ) {
390 if ( $prop->{db_type} eq 'integer[]' ) {
391 my @sections = grep { $_ != $owner->id } $object->sections;
392 $object->sections( @sections );
393 } else {
394 $object->sections( undef );
395 }
396 $object->store;
397 }
398 }
399 }
400 }
401 $m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : ''));
402 386 ahitrov }
403 8 ahitrov@rambler.ru
404 621 ahitrov unless (defined $request->{section_accesses}->{$id}) {
405 $request->{section_accesses}->{$id} = $user->get_section_access($id);
406 }
407 my $section_access = $request->{section_accesses}->{$id};
408
409 my (@documents, $total);
410
411 my $s = $owner->id;
412 my $sorted = $owner->_sorted();
413 $s .= ",$filter" if ($filter > 0);
414
415 8 ahitrov@rambler.ru my %filter=();
416 131 ahitrov my $nothing_found = 0;
417 8 ahitrov@rambler.ru my %order = (not $class and $owner->order_by) ? (order_by => $owner->order_by) : (order => ['date','direct']);
418 if (defined $alpha and $alpha ne '') {
419 $filter{ilike}=1;
420 $filter{ $alpha_search || 'name' }="$alpha%";
421 $order{order}=['name','reverse'];
422 delete $order{order_by};
423 }
424 if ( $class ) {
425 $filter{class} = $class;
426 } elsif ( $owner->default_document_class ) {
427 $filter{class} = $owner->default_document_class;
428 } elsif ( $owner->default_table_class ) {
429 $filter{table} = $owner->default_table_class;
430 }
431 $filter{s}=$s unless ($class && !$use_section);
432 if ( $search_by && defined $search ) {
433 my $doc_class = $class || $owner->default_document_class;
434 if ( $doc_class ) {
435 my @props = $doc_class->new( $keeper )->structure();
436 my ($prop) = grep { $_->{attr} eq $search_by } @props if @props;
437 131 ahitrov if ( ref $prop && ($prop->{type} eq 'integer' || $prop->{type} eq 'checkbox' ||
438 546 ahitrov (($prop->{type} eq 'pickup' || $prop->{type} eq 'lookup' || $prop->{type} eq 'status') && $search =~ /^\d+$/) ||
439 137 ahitrov (exists $prop->{db_type} && $prop->{db_type} =~ /integer\[\]/) )) {
440 8 ahitrov@rambler.ru $filter{$search_by} = int($search);
441 546 ahitrov } elsif ( ref $prop && $prop->{type} eq 'status' && $search =~ /\D/ ) {
442 my $str;
443 foreach my $pair ( @{$prop->{cases}} ) {
444 if ( lc(Encode::decode('utf-8', $pair->[1])) eq lc(Encode::decode('utf-8', $search)) || lc(Encode::decode('utf-8', $pair->[0])) eq lc(Encode::decode('utf-8', $search)) ) {
445 $str = $pair->[0];
446 last;
447 }
448 }
449 if ( $str ) {
450 $filter{$search_by} = $str;
451 }
452 131 ahitrov } elsif ( ref $prop && ($prop->{type} eq 'pickup' || $prop->{type} eq 'lookup') && $search =~ /\D/ ) {
453 my $lookup_opts = $prop->{lookup_opts};
454 386 ahitrov if ( ref $lookup_opts && (exists $lookup_opts->{class} || exists $lookup_opts->{table}) ) {
455 131 ahitrov my $search_field = exists $lookup_opts->{search_by} ? $lookup_opts->{search_by} : 'name';
456 my @ids = $keeper->get_documents (
457 ids => 1,
458 386 ahitrov exists $lookup_opts->{class} ? (class => $lookup_opts->{class}) : (table => $lookup_opts->{table}),
459 131 ahitrov ilike => 1,
460 $search_field => '%'.$search.'%',
461 );
462 if ( @ids ) {
463 $filter{$search_by} = \@ids;
464 } else {
465 $nothing_found = 1;
466 }
467 }
468 8 ahitrov@rambler.ru } else {
469 $filter{$search_by}='%'.$search.'%';
470 $filter{ilike} = 1;
471 }
472 } else {
473 $filter{$search_by}='%'.$search.'%';
474 $filter{ilike} = 1;
475 }
476 }
477
478 131 ahitrov # Дополнительные фильтры раздела
479 if ($owner->filters) {
480 no strict 'vars';
481 my $filters = eval($owner->filters);
482 if ($@) {
483 warn "Bad filter: " . $owner->filters . " in section " . $owner->id;
484 } elsif (ref $filters eq 'HASH') {
485 while ( my ($key, $val) = each %$filters ) {
486 $filter{$key} = $val;
487 }
488 }
489 }
490 8 ahitrov@rambler.ru
491 118 ahitrov $total = $keeper->get_documents(%filter, count=>1) unless $owner->no_count;
492 8 ahitrov@rambler.ru
493 616 ahitrov my $n = ref $owner && $owner->_page_size ? $owner->_page_size : 40;
494 8 ahitrov@rambler.ru my $first = $n * ($p - 1);
495 118 ahitrov ($first,$p)=(0,0) if (!$owner->no_count && $first>$total);
496 8 ahitrov@rambler.ru
497 131 ahitrov unless ( $nothing_found ) {
498 if ($class && !$use_section) {
499 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
500 } elsif ($sorted) {
501 607 ahitrov @documents = $keeper->get_sorted_documents(%filter);
502 131 ahitrov } else {
503 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
504 }
505 8 ahitrov@rambler.ru }
506 # набор колонок таблицы документов...
507 131 ahitrov my @columns = $sorted ? ({attr => '_sort_', name => 'N'}) : ();
508 8 ahitrov@rambler.ru
509 131 ahitrov # пытаемся найти колонки, которые документ сам пожелал показать (required_properties -> column)...
510 if ($filter{class} or @documents and $documents[0]) {
511 push @columns,
512 sort {$a->{column} <=> $b->{column}}
513 grep {$_->{column}} ($filter{class} ? $filter{class}->new($keeper)->structure : $documents[0]->structure);
514 }
515 8 ahitrov@rambler.ru
516 131 ahitrov # стандартная жопка таблицы...
517 @columns = (@columns,
518 {attr => '_act_', rusname => 'Действия'},
519 );
520
521 8 ahitrov@rambler.ru </%init>