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