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