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%"> </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 |
|
|
% if ($total > 0) { |
73 |
|
|
(всего: <% $total %>, показано с <% $first + 1 %> по <% ($first + $n > $total) ? $total : $first + $n %>) |
74 |
|
|
% } |
75 |
|
|
</legend> |
76 |
|
|
|
77 |
|
|
% if ($total or defined($alpha) or defined($search) ) { |
78 |
|
|
% if ($section_access == 2) { |
79 |
|
|
<& "/contenido/components/new_objects_form.msn", proto => 'documents', |
80 |
|
|
sect_id => $owner->id, |
81 |
|
|
default => ($owner->default_document_class ? $owner->default_document_class : undef) &> |
82 |
|
|
% } |
83 |
|
|
<div style="font-size:75%; font-family:Arial;"> |
84 |
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%" style="margin:4px 0 0; border:1px solid gray;"> |
85 |
|
|
<tr bgcolor="#e0e0e0"><th colspan="4">Поиск по букве: [<a href="?id=<% $id %>" style="font-weight:normal;">сброс фильтра</a>]</th></tr> |
86 |
|
|
<tr><td style="font-size:75%; font-family:Arial; padding:2px 4px;"> |
87 |
|
|
<& /inc/alpha.msn, alpha=>$alpha, params=>\%ARGS, &> |
88 |
|
|
</td></tr></table> |
89 |
|
|
% ## Форма поиска. Работает при включенном фильтре класса |
90 |
|
|
% ## и описанной для класса функции search_fields |
91 |
|
|
% ######################################################## |
92 |
|
|
% if ( $filter{class} ) { |
93 |
|
|
% my $document = $filter{class}->new ($keeper); |
94 |
|
|
% my @fields = $document->search_fields; |
95 |
|
|
% if ( @fields ) { |
96 |
|
|
% my @props = $document->required_properties; |
97 |
|
|
<form action="sections.html"> |
98 |
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%" style="margin:4px 0; border:1px solid gray;"> |
99 |
|
|
<tr bgcolor="#e0e0e0"><th colspan="4">Поиск по полю: [<a href="?id=<% $id %>" style="font-weight:normal;">сброс фильтра</a>]</th></tr><tr> |
100 |
|
|
<td width="1%" nowrap style="padding:2px 0 2px 4px;"><select name="search_by"> |
101 |
|
|
% foreach my $field ( @fields ) { |
102 |
|
|
% my ($prop) = grep { $_->{'attr'} eq $field } @props; |
103 |
|
|
% my $selected = $field eq $search_by ? ' selected' : ''; |
104 |
|
|
<option value="<% $field %>"<% $selected %>><% ref $prop ? $prop->{'shortname'} || $prop->{'rusname'} : $field %> |
105 |
|
|
% } |
106 |
|
|
</td><td width="0">:</td> |
107 |
|
|
<td width="98%"><input type="text" name="search" value="<% $search %>" style="width:100%"></td> |
108 |
|
|
<td width="1%" style="padding:2px 4px 2px 0;"><input type="submit" value=" » " style="border:1px solid gray;"></td> |
109 |
|
|
</tr></table> |
110 |
|
|
% if ( $id ) { |
111 |
|
|
<input type="hidden" name="id" value="<% $id %>"> |
112 |
|
|
% } |
113 |
|
|
% if ( $class ) { |
114 |
|
|
<input type="hidden" name="class" value="<% $class %>"> |
115 |
|
|
% } |
116 |
|
|
% if ( $use_section ) { |
117 |
|
|
<input type="hidden" name="use_section" value="<% $use_section %>"> |
118 |
|
|
% } |
119 |
|
|
</form> |
120 |
|
|
% } |
121 |
|
|
% } |
122 |
|
|
|
123 |
|
|
<div style="height:5px"><spacer type="block" height="5"></div> |
124 |
|
|
<& /inc/pages_.msn, p=>$p, n=>$n, total=>$total, href=>'sections.html', params=>\%ARGS, &> |
125 |
|
|
</div> |
126 |
|
|
|
127 |
|
|
<& /contenido/components/section_browse.msn, documents => \@documents, columns => \@columns, section => $owner, filter => \%filter_params, %ARGS &> |
128 |
|
|
|
129 |
|
|
<div style="font-size:75%; font-family:Arial;"> |
130 |
|
|
<& /inc/pages_.msn, p=>$p, n=>$n, total=>$total, href=>'sections.html', params=>\%ARGS, &> |
131 |
|
|
<div style="height:5px"><spacer type="block" height="5"></div> |
132 |
|
|
</div> |
133 |
|
|
|
134 |
|
|
% } else { |
135 |
|
|
<h4 align="center"><i>---- Нет документов -----</i></h4> |
136 |
|
|
% } |
137 |
|
|
% |
138 |
|
|
% if ($section_access == 2) { |
139 |
|
|
<& "/contenido/components/new_objects_form.msn", proto => 'documents', |
140 |
|
|
sect_id => $owner->id, |
141 |
|
|
default => ($owner->default_document_class ? $owner->default_document_class : undef) &> |
142 |
|
|
% } |
143 |
|
|
|
144 |
|
|
</fieldset> |
145 |
|
|
</td> |
146 |
|
|
</tr> |
147 |
|
|
</table> |
148 |
|
|
|
149 |
|
|
% } |
150 |
|
|
|
151 |
|
|
</body> |
152 |
|
|
</html> |
153 |
|
|
<%args> |
154 |
|
|
|
155 |
|
|
$id => undef |
156 |
|
|
$p => 1 |
157 |
|
|
$class => undef |
158 |
|
|
$use_section => undef |
159 |
|
|
$alpha => undef |
160 |
|
|
$alpha_search => undef |
161 |
|
|
$search_by => undef |
162 |
|
|
$search => undef |
163 |
|
|
$update => undef |
164 |
|
|
$delete => undef |
165 |
|
|
|
166 |
|
|
</%args> |
167 |
|
|
<%init> |
168 |
|
|
|
169 |
|
|
$id = 0 if $id =~ /\D/; |
170 |
|
|
my $owner; |
171 |
|
|
|
172 |
|
|
# Операции... |
173 |
|
|
if ($id && ($id > 0)) |
174 |
|
|
{ |
175 |
|
|
$owner = $keeper->get_section_by_id($id); |
176 |
|
|
} |
177 |
|
|
if (! ref($owner)) |
178 |
|
|
{ |
179 |
|
|
return undef; |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
my %filter_params; |
183 |
|
|
$filter_params{use_section} = $use_section if $use_section; |
184 |
|
|
$filter_params{class} = $class if $class; |
185 |
|
|
$filter_params{alpha} = $alpha if $alpha; |
186 |
|
|
$filter_params{alpha_search} = $alpha_search if $alpha_search; |
187 |
|
|
$filter_params{search_by} = $search_by if $search_by; |
188 |
|
|
$filter_params{search} = $search if $search; |
189 |
|
|
$filter_params{p} = $p if $p > 1; |
190 |
|
|
$filter_params{s} = $id if $id; |
191 |
|
|
|
192 |
16 |
ahitrov@rambler.ru |
# Фильтры работают в любом случае... |
193 |
8 |
ahitrov@rambler.ru |
my $filter = $m->comp('/contenido/components/context.msn', name => 'filter'); |
194 |
|
|
my $profile = $m->comp('/contenido/components/context.msn', name => 'profile'); |
195 |
|
|
|
196 |
|
|
unless (defined $request->{section_accesses}->{$id}) |
197 |
|
|
{ |
198 |
|
|
$request->{section_accesses}->{$id} = $user->get_section_access($id); |
199 |
|
|
} |
200 |
|
|
my $section_access = $request->{section_accesses}->{$id}; |
201 |
|
|
|
202 |
|
|
my (@documents, $total); |
203 |
|
|
|
204 |
|
|
my $s = $owner->id; |
205 |
|
|
my $sorted = $owner->_sorted(); |
206 |
|
|
$s .= ",$filter" if ($filter > 0); |
207 |
|
|
|
208 |
|
|
if ($update) { |
209 |
|
|
my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params ); |
210 |
|
|
my %updated; |
211 |
|
|
while ( my ($field, $value) = each %ARGS ) { |
212 |
|
|
if ( $field =~ /^update_(\d+)_(\w+)$/ ) { |
213 |
|
|
my $oid = $1; |
214 |
|
|
my $attr = $2; |
215 |
|
|
$updated{$oid}{$attr} = $value; |
216 |
|
|
} |
217 |
|
|
} |
218 |
|
|
my %classes = map { $_->{class} => 1 } values %updated; |
219 |
|
|
foreach my $update_class ( keys %classes ) { |
220 |
|
|
my @ids; |
221 |
|
|
while ( my ($oid, $attr) = each %updated) { |
222 |
|
|
push @ids, $oid if $attr->{class} eq $update_class; |
223 |
|
|
} |
224 |
|
|
my @objects = $keeper->get_documents ( |
225 |
|
|
id => \@ids, |
226 |
|
|
class => $update_class |
227 |
|
|
) if @ids; |
228 |
|
|
foreach my $object ( @objects ) { |
229 |
|
|
my $document_access = $user->section_accesses($user, $object->section); |
230 |
|
|
next unless $document_access == 2; |
231 |
|
|
my $fields = $updated{$object->id}; |
232 |
|
|
my @props = grep { exists $_->{inline} && $_->{inline} } $object->structure; |
233 |
|
|
if ( ref $fields eq 'HASH' ) { |
234 |
|
|
foreach my $prop ( @props ) { |
235 |
|
|
my $attr = $prop->{attr}; |
236 |
|
|
my $value = ref $fields && exists $fields->{$attr} ? $fields->{$attr} : undef; |
237 |
|
|
if ( $prop->{db_type} eq 'float' ) { |
238 |
|
|
for ( $value ) { |
239 |
|
|
s/\,/\./; |
240 |
|
|
s/^\s+//; |
241 |
|
|
s/\s+$//; |
242 |
|
|
} |
243 |
|
|
} |
244 |
|
|
if ( $prop->{type} eq 'checkbox' ) { |
245 |
|
|
$value = $value ? 1 : undef; |
246 |
|
|
} |
247 |
|
|
|
248 |
|
|
$object->$attr($value); |
249 |
|
|
} |
250 |
|
|
$object->store; |
251 |
|
|
} |
252 |
|
|
} |
253 |
|
|
} |
254 |
|
|
$m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : '')); |
255 |
|
|
} |
256 |
|
|
if ( $delete ) { |
257 |
|
|
my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params ); |
258 |
|
|
my %deleted; |
259 |
|
|
while ( my ($field, $value) = each %ARGS ) { |
260 |
|
|
if ( $field =~ /^delete_(\d+)_(\w+)$/ ) { |
261 |
|
|
my $oid = $1; |
262 |
|
|
my $attr = $2; |
263 |
|
|
$deleted{$oid}{$attr} = $value; |
264 |
|
|
} |
265 |
|
|
} |
266 |
|
|
my %classes = map { $_->{class} => 1 } values %deleted; |
267 |
|
|
foreach my $delete_class ( keys %classes ) { |
268 |
|
|
my @ids; |
269 |
|
|
while ( my ($oid, $attr) = each %deleted) { |
270 |
|
|
push @ids, $oid if exists $attr->{id} && $attr->{id} && ($attr->{class} eq $delete_class); |
271 |
|
|
} |
272 |
|
|
my @objects = $keeper->get_documents ( |
273 |
|
|
id => \@ids, |
274 |
|
|
class => $delete_class |
275 |
|
|
) if @ids; |
276 |
|
|
foreach my $object ( @objects ) { |
277 |
|
|
my $document_access = $user->section_accesses($user, $object->section); |
278 |
|
|
next unless $document_access == 2; |
279 |
|
|
$object->delete; |
280 |
|
|
} |
281 |
|
|
} |
282 |
|
|
$m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : '')); |
283 |
|
|
} |
284 |
|
|
|
285 |
|
|
my %filter=(); |
286 |
|
|
my %order = (not $class and $owner->order_by) ? (order_by => $owner->order_by) : (order => ['date','direct']); |
287 |
|
|
if (defined $alpha and $alpha ne '') { |
288 |
|
|
$filter{ilike}=1; |
289 |
|
|
$filter{ $alpha_search || 'name' }="$alpha%"; |
290 |
|
|
$order{order}=['name','reverse']; |
291 |
|
|
delete $order{order_by}; |
292 |
|
|
} |
293 |
|
|
if ( $class ) { |
294 |
|
|
$filter{class} = $class; |
295 |
|
|
} elsif ( $owner->default_document_class ) { |
296 |
|
|
$filter{class} = $owner->default_document_class; |
297 |
|
|
} elsif ( $owner->default_table_class ) { |
298 |
|
|
$filter{table} = $owner->default_table_class; |
299 |
|
|
} |
300 |
|
|
$filter{s}=$s unless ($class && !$use_section); |
301 |
|
|
if ( $search_by && defined $search ) { |
302 |
|
|
my $doc_class = $class || $owner->default_document_class; |
303 |
|
|
if ( $doc_class ) { |
304 |
|
|
my @props = $doc_class->new( $keeper )->structure(); |
305 |
|
|
my ($prop) = grep { $_->{attr} eq $search_by } @props if @props; |
306 |
16 |
ahitrov@rambler.ru |
if ( ref $prop && ($prop->{type} eq 'integer' || $prop->{type} eq 'checkbox') ) { |
307 |
8 |
ahitrov@rambler.ru |
$filter{$search_by} = int($search); |
308 |
|
|
} else { |
309 |
|
|
$filter{$search_by}='%'.$search.'%'; |
310 |
|
|
$filter{ilike} = 1; |
311 |
|
|
} |
312 |
|
|
} else { |
313 |
|
|
$filter{$search_by}='%'.$search.'%'; |
314 |
|
|
$filter{ilike} = 1; |
315 |
|
|
} |
316 |
|
|
} |
317 |
|
|
|
318 |
|
|
# Дополнительные фильтры раздела |
319 |
|
|
if ($owner->filters) { |
320 |
|
|
no strict 'vars'; |
321 |
|
|
my $filters = eval($owner->filters); |
322 |
|
|
if ($@) { |
323 |
|
|
warn "Bad filter: " . $owner->filters . " in section " . $owner->id; |
324 |
|
|
} elsif (ref $filters eq 'HASH') { |
325 |
|
|
map { $filter{$_} = $filters->{$_} } keys %$filters; |
326 |
|
|
} |
327 |
|
|
} |
328 |
|
|
|
329 |
|
|
$total = $keeper->get_documents(%filter, count=>1); |
330 |
|
|
|
331 |
|
|
my $n = 40; |
332 |
|
|
my $first = $n * ($p - 1); |
333 |
|
|
($first,$p)=(0,0) if ($first>$total); |
334 |
|
|
|
335 |
|
|
if ($class && !$use_section) { |
336 |
|
|
@documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first); |
337 |
|
|
} elsif ($sorted) { |
338 |
|
|
@documents = $keeper->get_sorted_documents(%filter, limit=>$n, offset=>$first); |
339 |
|
|
} else { |
340 |
|
|
@documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first); |
341 |
|
|
} |
342 |
|
|
|
343 |
|
|
# набор колонок таблицы документов... |
344 |
|
|
my @columns = $sorted ? ({attr => '_sort_', name => 'N'}) : (); |
345 |
|
|
|
346 |
|
|
# пытаемся найти колонки, которые документ сам пожелал показать (required_properties -> column)... |
347 |
|
|
if ($filter{class} or @documents and $documents[0]) { |
348 |
|
|
push @columns, |
349 |
|
|
sort {$a->{column} <=> $b->{column}} |
350 |
|
|
grep {$_->{column}} ($filter{class} ? $filter{class}->new($keeper)->structure : $documents[0]->structure); |
351 |
|
|
} |
352 |
|
|
|
353 |
|
|
# стандартная жопка таблицы... |
354 |
|
|
@columns = (@columns, |
355 |
|
|
{attr => '_act_', rusname => 'Действия'}, |
356 |
|
|
); |
357 |
|
|
</%init> |