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 unless (defined $request->{section_accesses}->{$id})
222 {
223 $request->{section_accesses}->{$id} = $user->get_section_access($id);
224 }
225 my $section_access = $request->{section_accesses}->{$id};
226
227 my (@documents, $total);
228
229 my $s = $owner->id;
230 my $sorted = $owner->_sorted();
231 $s .= ",$filter" if ($filter > 0);
232
233 if ($update) {
234 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
235 my %updated;
236 while ( my ($field, $value) = each %ARGS ) {
237 if ( $field =~ /^update_(\d+)_(\w+)$/ ) {
238 my $oid = $1;
239 my $attr = $2;
240 $updated{$oid}{$attr} = $value;
241 }
242 }
243 my %classes = map { $_->{class} => 1 } values %updated;
244 foreach my $update_class ( keys %classes ) {
245 my @ids;
246 while ( my ($oid, $attr) = each %updated) {
247 push @ids, $oid if $attr->{class} eq $update_class;
248 }
249 my @objects = $keeper->get_documents (
250 id => \@ids,
251 class => $update_class
252 ) if @ids;
253 foreach my $object ( @objects ) {
254 my $document_access = $user->section_accesses($user, $object->section);
255 next unless $document_access == 2;
256 my $fields = $updated{$object->id};
257 my @props = grep { exists $_->{inline} && $_->{inline} } $object->structure;
258 if ( ref $fields eq 'HASH' ) {
259 foreach my $prop ( @props ) {
260 my $attr = $prop->{attr};
261 my $value = ref $fields && exists $fields->{$attr} ? $fields->{$attr} : undef;
262 395 ahitrov if ( $prop->{type} eq 'checkbox' ) {
263 $value = $value ? 1 : undef;
264 }
265 386 ahitrov if ( exists $prop->{db_type} ) {
266 if ( $prop->{db_type} eq 'float' ) {
267 for ( $value ) {
268 s/\,/\./;
269 s/^\s+//;
270 s/\s+$//;
271 }
272 if ( $value eq '' ) {
273 $value = undef;
274 }
275 } elsif ( $prop->{db_type} eq 'integer' || $prop->{db_type} eq 'smallint' ) {
276 $value =~ s/\D//sg if $value;
277 if ( $value eq '' ) {
278 $value = undef;
279 }
280 8 ahitrov@rambler.ru }
281 }
282
283 $object->$attr($value);
284 }
285 $object->store;
286 }
287 }
288 }
289 $m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : ''));
290 }
291 if ( $delete ) {
292 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
293 my %deleted;
294 while ( my ($field, $value) = each %ARGS ) {
295 if ( $field =~ /^delete_(\d+)_(\w+)$/ ) {
296 my $oid = $1;
297 my $attr = $2;
298 $deleted{$oid}{$attr} = $value;
299 }
300 }
301 my %classes = map { $_->{class} => 1 } values %deleted;
302 foreach my $delete_class ( keys %classes ) {
303 my @ids;
304 while ( my ($oid, $attr) = each %deleted) {
305 push @ids, $oid if exists $attr->{id} && $attr->{id} && ($attr->{class} eq $delete_class);
306 }
307 my @objects = $keeper->get_documents (
308 id => \@ids,
309 class => $delete_class
310 ) if @ids;
311 foreach my $object ( @objects ) {
312 my $document_access = $user->section_accesses($user, $object->section);
313 next unless $document_access == 2;
314 $object->delete;
315 }
316 }
317 $m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : ''));
318 }
319 386 ahitrov if ( $ARGS{move} || $ARGS{link} ) {
320 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
321 if ( exists $ARGS{tree} && $ARGS{tree} && $ARGS{tree} != $owner->id ) {
322 my %updated;
323 while ( my ($field, $value) = each %ARGS ) {
324 388 ahitrov if ( $field =~ /^delete_(\d+)_(\w+)$/ ) {
325 386 ahitrov my $oid = $1;
326 my $attr = $2;
327 $updated{$oid}{$attr} = $value;
328 }
329 }
330 522 ahitrov warn Dumper \%updated if $DEBUG;
331 386 ahitrov my %classes = map { $_->{class} => 1 } values %updated;
332 my $parent_new = $keeper->get_section_by_id( $ARGS{tree} );
333 my $document_access = $user->section_accesses($user, $parent_new->id);
334 if ( $document_access == 2 ) {
335 foreach my $update_class ( keys %classes ) {
336 my @ids;
337 while ( my ($oid, $attr) = each %updated) {
338 388 ahitrov push @ids, $oid if exists $attr->{id} && $attr->{id} && ($attr->{class} eq $update_class);
339 386 ahitrov }
340 my @objects = $keeper->get_documents (
341 id => \@ids,
342 class => $update_class
343 ) if @ids;
344 my ($prop) = grep { $_->{attr} eq 'sections' } $update_class->new( $keeper )->structure;
345 if ( ref $prop && exists $prop->{db_type} && exists $prop->{db_field} ) {
346 foreach my $object ( @objects ) {
347 if ( $prop->{db_type} eq 'integer[]' ) {
348 my @sections = grep { $_ != $parent_new->id } $object->sections;
349 if ( @sections && $sections[0] == $owner->id ) {
350 419 ahitrov if ( $ARGS{move} ) {
351 shift @sections;
352 unshift @sections, $parent_new->id;
353 } else {
354 push @sections, $parent_new->id;
355 }
356 } else {
357 if ( $ARGS{move} ) {
358 @sections = grep { $_ != $owner->id } @sections;
359 }
360 521 ahitrov push @sections, $parent_new->id;
361 386 ahitrov }
362 $object->sections( @sections );
363 } else {
364 $object->sections( $parent_new->id );
365 }
366 $object->store;
367 }
368 }
369 }
370 }
371 }
372 $m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : ''));
373 522 ahitrov } elsif ( $ARGS{unlink} ) {
374 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
375 my $document_access = $user->section_accesses($user, $owner->id);
376 my %updated;
377 while ( my ($field, $value) = each %ARGS ) {
378 if ( $field =~ /^delete_(\d+)_(\w+)$/ ) {
379 my $oid = $1;
380 my $attr = $2;
381 $updated{$oid}{$attr} = $value;
382 }
383 }
384 warn Dumper \%updated if $DEBUG;
385 my %classes = map { $_->{class} => 1 } values %updated;
386 if ( $document_access == 2 ) {
387 foreach my $update_class ( keys %classes ) {
388 my @ids;
389 while ( my ($oid, $attr) = each %updated) {
390 push @ids, $oid if exists $attr->{id} && $attr->{id} && ($attr->{class} eq $update_class);
391 }
392 my @objects = $keeper->get_documents (
393 id => \@ids,
394 class => $update_class
395 ) if @ids;
396 my ($prop) = grep { $_->{attr} eq 'sections' } $update_class->new( $keeper )->structure;
397 if ( ref $prop && exists $prop->{db_type} && exists $prop->{db_field} ) {
398 foreach my $object ( @objects ) {
399 if ( $prop->{db_type} eq 'integer[]' ) {
400 my @sections = grep { $_ != $owner->id } $object->sections;
401 $object->sections( @sections );
402 } else {
403 $object->sections( undef );
404 }
405 $object->store;
406 }
407 }
408 }
409 }
410 $m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : ''));
411 386 ahitrov }
412 8 ahitrov@rambler.ru
413 my %filter=();
414 131 ahitrov my $nothing_found = 0;
415 8 ahitrov@rambler.ru my %order = (not $class and $owner->order_by) ? (order_by => $owner->order_by) : (order => ['date','direct']);
416 if (defined $alpha and $alpha ne '') {
417 $filter{ilike}=1;
418 $filter{ $alpha_search || 'name' }="$alpha%";
419 $order{order}=['name','reverse'];
420 delete $order{order_by};
421 }
422 if ( $class ) {
423 $filter{class} = $class;
424 } elsif ( $owner->default_document_class ) {
425 $filter{class} = $owner->default_document_class;
426 } elsif ( $owner->default_table_class ) {
427 $filter{table} = $owner->default_table_class;
428 }
429 $filter{s}=$s unless ($class && !$use_section);
430 if ( $search_by && defined $search ) {
431 my $doc_class = $class || $owner->default_document_class;
432 if ( $doc_class ) {
433 my @props = $doc_class->new( $keeper )->structure();
434 my ($prop) = grep { $_->{attr} eq $search_by } @props if @props;
435 131 ahitrov if ( ref $prop && ($prop->{type} eq 'integer' || $prop->{type} eq 'checkbox' ||
436 546 ahitrov (($prop->{type} eq 'pickup' || $prop->{type} eq 'lookup' || $prop->{type} eq 'status') && $search =~ /^\d+$/) ||
437 137 ahitrov (exists $prop->{db_type} && $prop->{db_type} =~ /integer\[\]/) )) {
438 8 ahitrov@rambler.ru $filter{$search_by} = int($search);
439 546 ahitrov } elsif ( ref $prop && $prop->{type} eq 'status' && $search =~ /\D/ ) {
440 my $str;
441 foreach my $pair ( @{$prop->{cases}} ) {
442 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)) ) {
443 $str = $pair->[0];
444 last;
445 }
446 }
447 if ( $str ) {
448 $filter{$search_by} = $str;
449 }
450 131 ahitrov } elsif ( ref $prop && ($prop->{type} eq 'pickup' || $prop->{type} eq 'lookup') && $search =~ /\D/ ) {
451 my $lookup_opts = $prop->{lookup_opts};
452 386 ahitrov if ( ref $lookup_opts && (exists $lookup_opts->{class} || exists $lookup_opts->{table}) ) {
453 131 ahitrov my $search_field = exists $lookup_opts->{search_by} ? $lookup_opts->{search_by} : 'name';
454 my @ids = $keeper->get_documents (
455 ids => 1,
456 386 ahitrov exists $lookup_opts->{class} ? (class => $lookup_opts->{class}) : (table => $lookup_opts->{table}),
457 131 ahitrov ilike => 1,
458 $search_field => '%'.$search.'%',
459 );
460 if ( @ids ) {
461 $filter{$search_by} = \@ids;
462 } else {
463 $nothing_found = 1;
464 }
465 }
466 8 ahitrov@rambler.ru } else {
467 $filter{$search_by}='%'.$search.'%';
468 $filter{ilike} = 1;
469 }
470 } else {
471 $filter{$search_by}='%'.$search.'%';
472 $filter{ilike} = 1;
473 }
474 }
475
476 131 ahitrov # Дополнительные фильтры раздела
477 if ($owner->filters) {
478 no strict 'vars';
479 my $filters = eval($owner->filters);
480 if ($@) {
481 warn "Bad filter: " . $owner->filters . " in section " . $owner->id;
482 } elsif (ref $filters eq 'HASH') {
483 while ( my ($key, $val) = each %$filters ) {
484 $filter{$key} = $val;
485 }
486 }
487 }
488 8 ahitrov@rambler.ru
489 118 ahitrov $total = $keeper->get_documents(%filter, count=>1) unless $owner->no_count;
490 8 ahitrov@rambler.ru
491 616 ahitrov my $n = ref $owner && $owner->_page_size ? $owner->_page_size : 40;
492 8 ahitrov@rambler.ru my $first = $n * ($p - 1);
493 118 ahitrov ($first,$p)=(0,0) if (!$owner->no_count && $first>$total);
494 8 ahitrov@rambler.ru
495 131 ahitrov unless ( $nothing_found ) {
496 if ($class && !$use_section) {
497 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
498 } elsif ($sorted) {
499 607 ahitrov @documents = $keeper->get_sorted_documents(%filter);
500 131 ahitrov } else {
501 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
502 }
503 8 ahitrov@rambler.ru }
504 # набор колонок таблицы документов...
505 131 ahitrov my @columns = $sorted ? ({attr => '_sort_', name => 'N'}) : ();
506 8 ahitrov@rambler.ru
507 131 ahitrov # пытаемся найти колонки, которые документ сам пожелал показать (required_properties -> column)...
508 if ($filter{class} or @documents and $documents[0]) {
509 push @columns,
510 sort {$a->{column} <=> $b->{column}}
511 grep {$_->{column}} ($filter{class} ? $filter{class}->new($keeper)->structure : $documents[0]->structure);
512 }
513 8 ahitrov@rambler.ru
514 131 ahitrov # стандартная жопка таблицы...
515 @columns = (@columns,
516 {attr => '_act_', rusname => 'Действия'},
517 );
518
519 8 ahitrov@rambler.ru </%init>