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 8 ahitrov@rambler.ru % if ($section_access == 2) {
80 <& "/contenido/components/new_objects_form.msn", proto => 'documents',
81 450 ahitrov sect_id => $owner->id, section => $owner,
82 8 ahitrov@rambler.ru default => ($owner->default_document_class ? $owner->default_document_class : undef) &>
83 % }
84 117 ahitrov <div style="font-size:12px; font-family:Arial;">
85 8 ahitrov@rambler.ru <table border="0" cellspacing="0" cellpadding="2" width="100%" style="margin:4px 0 0; border:1px solid gray;">
86 <tr bgcolor="#e0e0e0"><th colspan="4">Поиск по букве:&nbsp;&nbsp;[<a href="?id=<% $id %>" style="font-weight:normal;">сброс фильтра</a>]</th></tr>
87 117 ahitrov <tr><td style="font-size:12px; font-family:Arial; padding:2px 4px;">
88 8 ahitrov@rambler.ru <& /inc/alpha.msn, alpha=>$alpha, params=>\%ARGS, &>
89 </td></tr></table>
90 % ## Форма поиска. Работает при включенном фильтре класса
91 % ## и описанной для класса функции search_fields
92 % ########################################################
93 450 ahitrov % if ( $filter{class} || $filter{table} ) {
94 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 };
95 8 ahitrov@rambler.ru % my @fields = $document->search_fields;
96 % if ( @fields ) {
97 % my @props = $document->required_properties;
98 <form action="sections.html">
99 <table border="0" cellspacing="0" cellpadding="2" width="100%" style="margin:4px 0; border:1px solid gray;">
100 <tr bgcolor="#e0e0e0"><th colspan="4">Поиск по полю:&nbsp;&nbsp;[<a href="?id=<% $id %>" style="font-weight:normal;">сброс фильтра</a>]</th></tr><tr>
101 <td width="1%" nowrap style="padding:2px 0 2px 4px;"><select name="search_by">
102 % foreach my $field ( @fields ) {
103 % my ($prop) = grep { $_->{'attr'} eq $field } @props;
104 % my $selected = $field eq $search_by ? ' selected' : '';
105 <option value="<% $field %>"<% $selected %>><% ref $prop ? $prop->{'shortname'} || $prop->{'rusname'} : $field %>
106 % }
107 </td><td width="0">:</td>
108 <td width="98%"><input type="text" name="search" value="<% $search %>" style="width:100%"></td>
109 <td width="1%" style="padding:2px 4px 2px 0;"><input type="submit" value=" &raquo; " style="border:1px solid gray;"></td>
110 </tr></table>
111 % if ( $id ) {
112 <input type="hidden" name="id" value="<% $id %>">
113 % }
114 % if ( $class ) {
115 <input type="hidden" name="class" value="<% $class %>">
116 % }
117 % if ( $use_section ) {
118 <input type="hidden" name="use_section" value="<% $use_section %>">
119 % }
120 </form>
121 % }
122 % }
123
124 <div style="height:5px"><spacer type="block" height="5"></div>
125 118 ahitrov % if ( $owner->no_count ) {
126 <& /inc/pages_nocount.msn, p=>$p, n=>$n, found=> scalar @documents, href=>'sections.html', params=>\%ARGS, size => 15 &>
127 % } else {
128 8 ahitrov@rambler.ru <& /inc/pages_.msn, p=>$p, n=>$n, total=>$total, href=>'sections.html', params=>\%ARGS, &>
129 118 ahitrov % }
130 8 ahitrov@rambler.ru </div>
131
132 <& /contenido/components/section_browse.msn, documents => \@documents, columns => \@columns, section => $owner, filter => \%filter_params, %ARGS &>
133
134 117 ahitrov <div style="font-size:12px; font-family:Arial;">
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 % } else {
138 8 ahitrov@rambler.ru <& /inc/pages_.msn, p=>$p, n=>$n, total=>$total, href=>'sections.html', params=>\%ARGS, &>
139 118 ahitrov % }
140 8 ahitrov@rambler.ru <div style="height:5px"><spacer type="block" height="5"></div>
141 </div>
142
143 % } else {
144 <h4 align="center"><i>---- Нет документов -----</i></h4>
145 % }
146 %
147 % if ($section_access == 2) {
148 <& "/contenido/components/new_objects_form.msn", proto => 'documents',
149 sect_id => $owner->id,
150 default => ($owner->default_document_class ? $owner->default_document_class : undef) &>
151 % }
152
153 </fieldset>
154 </td>
155 </tr>
156 </table>
157
158 % }
159
160 </body>
161 </html>
162 607 ahitrov <%once>
163
164 my $cookie_name = 'content_fullwidth';
165
166 </%once>
167 8 ahitrov@rambler.ru <%args>
168
169 $id => undef
170 $p => 1
171 $class => undef
172 $use_section => undef
173 $alpha => undef
174 $alpha_search => undef
175 $search_by => undef
176 $search => undef
177 $update => undef
178 $delete => undef
179
180 </%args>
181 <%init>
182
183 $id = 0 if $id =~ /\D/;
184 607 ahitrov my $content_fullwidth = $m->comp('/contenido/components/cookies.msn', name => $cookie_name);
185
186 8 ahitrov@rambler.ru my $owner;
187
188 # Операции...
189 if ($id && ($id > 0))
190 {
191 $owner = $keeper->get_section_by_id($id);
192 }
193 if (! ref($owner))
194 {
195 return undef;
196 }
197
198 my %filter_params;
199 $filter_params{use_section} = $use_section if $use_section;
200 $filter_params{class} = $class if $class;
201 $filter_params{alpha} = $alpha if $alpha;
202 $filter_params{alpha_search} = $alpha_search if $alpha_search;
203 $filter_params{search_by} = $search_by if $search_by;
204 $filter_params{search} = $search if $search;
205 $filter_params{p} = $p if $p > 1;
206 $filter_params{s} = $id if $id;
207
208 16 ahitrov@rambler.ru # Фильтры работают в любом случае...
209 8 ahitrov@rambler.ru my $filter = $m->comp('/contenido/components/context.msn', name => 'filter');
210 my $profile = $m->comp('/contenido/components/context.msn', name => 'profile');
211
212 unless (defined $request->{section_accesses}->{$id})
213 {
214 $request->{section_accesses}->{$id} = $user->get_section_access($id);
215 }
216 my $section_access = $request->{section_accesses}->{$id};
217
218 my (@documents, $total);
219
220 my $s = $owner->id;
221 my $sorted = $owner->_sorted();
222 $s .= ",$filter" if ($filter > 0);
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 my %filter=();
405 131 ahitrov my $nothing_found = 0;
406 8 ahitrov@rambler.ru my %order = (not $class and $owner->order_by) ? (order_by => $owner->order_by) : (order => ['date','direct']);
407 if (defined $alpha and $alpha ne '') {
408 $filter{ilike}=1;
409 $filter{ $alpha_search || 'name' }="$alpha%";
410 $order{order}=['name','reverse'];
411 delete $order{order_by};
412 }
413 if ( $class ) {
414 $filter{class} = $class;
415 } elsif ( $owner->default_document_class ) {
416 $filter{class} = $owner->default_document_class;
417 } elsif ( $owner->default_table_class ) {
418 $filter{table} = $owner->default_table_class;
419 }
420 $filter{s}=$s unless ($class && !$use_section);
421 if ( $search_by && defined $search ) {
422 my $doc_class = $class || $owner->default_document_class;
423 if ( $doc_class ) {
424 my @props = $doc_class->new( $keeper )->structure();
425 my ($prop) = grep { $_->{attr} eq $search_by } @props if @props;
426 131 ahitrov if ( ref $prop && ($prop->{type} eq 'integer' || $prop->{type} eq 'checkbox' ||
427 546 ahitrov (($prop->{type} eq 'pickup' || $prop->{type} eq 'lookup' || $prop->{type} eq 'status') && $search =~ /^\d+$/) ||
428 137 ahitrov (exists $prop->{db_type} && $prop->{db_type} =~ /integer\[\]/) )) {
429 8 ahitrov@rambler.ru $filter{$search_by} = int($search);
430 546 ahitrov } elsif ( ref $prop && $prop->{type} eq 'status' && $search =~ /\D/ ) {
431 my $str;
432 foreach my $pair ( @{$prop->{cases}} ) {
433 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)) ) {
434 $str = $pair->[0];
435 last;
436 }
437 }
438 if ( $str ) {
439 $filter{$search_by} = $str;
440 }
441 131 ahitrov } elsif ( ref $prop && ($prop->{type} eq 'pickup' || $prop->{type} eq 'lookup') && $search =~ /\D/ ) {
442 my $lookup_opts = $prop->{lookup_opts};
443 386 ahitrov if ( ref $lookup_opts && (exists $lookup_opts->{class} || exists $lookup_opts->{table}) ) {
444 131 ahitrov my $search_field = exists $lookup_opts->{search_by} ? $lookup_opts->{search_by} : 'name';
445 my @ids = $keeper->get_documents (
446 ids => 1,
447 386 ahitrov exists $lookup_opts->{class} ? (class => $lookup_opts->{class}) : (table => $lookup_opts->{table}),
448 131 ahitrov ilike => 1,
449 $search_field => '%'.$search.'%',
450 );
451 if ( @ids ) {
452 $filter{$search_by} = \@ids;
453 } else {
454 $nothing_found = 1;
455 }
456 }
457 8 ahitrov@rambler.ru } else {
458 $filter{$search_by}='%'.$search.'%';
459 $filter{ilike} = 1;
460 }
461 } else {
462 $filter{$search_by}='%'.$search.'%';
463 $filter{ilike} = 1;
464 }
465 }
466
467 131 ahitrov # Дополнительные фильтры раздела
468 if ($owner->filters) {
469 no strict 'vars';
470 my $filters = eval($owner->filters);
471 if ($@) {
472 warn "Bad filter: " . $owner->filters . " in section " . $owner->id;
473 } elsif (ref $filters eq 'HASH') {
474 while ( my ($key, $val) = each %$filters ) {
475 $filter{$key} = $val;
476 }
477 }
478 }
479 8 ahitrov@rambler.ru
480 118 ahitrov $total = $keeper->get_documents(%filter, count=>1) unless $owner->no_count;
481 8 ahitrov@rambler.ru
482 my $n = 40;
483 my $first = $n * ($p - 1);
484 118 ahitrov ($first,$p)=(0,0) if (!$owner->no_count && $first>$total);
485 8 ahitrov@rambler.ru
486 131 ahitrov unless ( $nothing_found ) {
487 if ($class && !$use_section) {
488 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
489 } elsif ($sorted) {
490 607 ahitrov @documents = $keeper->get_sorted_documents(%filter);
491 131 ahitrov } else {
492 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
493 }
494 8 ahitrov@rambler.ru }
495 # набор колонок таблицы документов...
496 131 ahitrov my @columns = $sorted ? ({attr => '_sort_', name => 'N'}) : ();
497 8 ahitrov@rambler.ru
498 131 ahitrov # пытаемся найти колонки, которые документ сам пожелал показать (required_properties -> column)...
499 if ($filter{class} or @documents and $documents[0]) {
500 push @columns,
501 sort {$a->{column} <=> $b->{column}}
502 grep {$_->{column}} ($filter{class} ? $filter{class}->new($keeper)->structure : $documents[0]->structure);
503 }
504 8 ahitrov@rambler.ru
505 131 ahitrov # стандартная жопка таблицы...
506 @columns = (@columns,
507 {attr => '_act_', rusname => 'Действия'},
508 );
509
510 8 ahitrov@rambler.ru </%init>