1 |
3 |
ahitrov@rambler.ru |
<%ARGS> |
2 |
|
|
|
3 |
|
|
$id => undef |
4 |
|
|
$class => undef |
5 |
|
|
$source_class => undef |
6 |
|
|
$dest_class => undef |
7 |
33 |
ahitrov@rambler.ru |
$update => undef |
8 |
3 |
ahitrov@rambler.ru |
|
9 |
|
|
</%ARGS> |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
<%init> |
13 |
33 |
ahitrov@rambler.ru |
if ($id) { |
14 |
3 |
ahitrov@rambler.ru |
my $document = $keeper->get_document_by_id($id, class=>$class); |
15 |
|
|
|
16 |
33 |
ahitrov@rambler.ru |
if ( $update ) { |
17 |
3 |
ahitrov@rambler.ru |
|
18 |
33 |
ahitrov@rambler.ru |
my %updated; |
19 |
|
|
while ( my ($field, $value) = each %ARGS ) { |
20 |
|
|
if ( $field =~ /^update_(\d+)_(\w+)$/ ) { |
21 |
|
|
my $oid = $1; |
22 |
|
|
my $attr = $2; |
23 |
|
|
$updated{$oid}{$attr} = $value; |
24 |
|
|
} |
25 |
|
|
} |
26 |
|
|
my %classes = map { $_->{class} => 1 } values %updated; |
27 |
|
|
foreach my $update_class ( keys %classes ) { |
28 |
|
|
my @ids; |
29 |
|
|
while ( my ($oid, $attr) = each %updated) { |
30 |
|
|
push @ids, $oid if $attr->{class} eq $update_class; |
31 |
|
|
} |
32 |
|
|
my @objects = $keeper->get_links ( |
33 |
|
|
id => \@ids, |
34 |
|
|
class => $update_class |
35 |
|
|
) if @ids; |
36 |
|
|
foreach my $object ( @objects ) { |
37 |
|
|
my $fields = $updated{$object->id}; |
38 |
|
|
my @props = grep { exists $_->{inline} && $_->{inline} } $object->structure; |
39 |
|
|
if ( ref $fields eq 'HASH' ) { |
40 |
|
|
foreach my $prop ( @props ) { |
41 |
|
|
my $attr = $prop->{attr}; |
42 |
|
|
my $value = ref $fields && exists $fields->{$attr} ? $fields->{$attr} : undef; |
43 |
|
|
if ( $prop->{db_type} eq 'float' ) { |
44 |
|
|
for ( $value ) { |
45 |
|
|
s/\,/\./; |
46 |
|
|
s/^\s+//; |
47 |
|
|
s/\s+$//; |
48 |
|
|
} |
49 |
|
|
} |
50 |
|
|
if ( $prop->{type} eq 'checkbox' ) { |
51 |
|
|
$value = $value ? 1 : undef; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
$object->$attr($value); |
55 |
|
|
} |
56 |
|
|
$object->store; |
57 |
|
|
} |
58 |
|
|
} |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
} else { |
62 |
|
|
my @link_args = (); |
63 |
|
|
if ( exists $ARGS{links} && ref $ARGS{links} eq 'ARRAY' ) { |
64 |
|
|
@link_args = @{ $ARGS{links} } |
65 |
|
|
} elsif ( exists $ARGS{links} ) { |
66 |
|
|
@link_args = ( $ARGS{links} ); |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
my %nlinks = (); |
70 |
|
|
foreach my $name (@link_args) |
71 |
3 |
ahitrov@rambler.ru |
{ |
72 |
33 |
ahitrov@rambler.ru |
if ($name =~ /^link_(\d+)_(\d+)_(.*)$/) |
73 |
|
|
{ |
74 |
|
|
my ($id, $dest_id, $lclass) = ($1, $2, $3); |
75 |
|
|
if ( $id && $lclass ) { |
76 |
|
|
my $link = $keeper->get_link_by_id ($id, |
77 |
|
|
class => $lclass, |
78 |
|
|
); |
79 |
|
|
$link->delete if ref $link; |
80 |
|
|
} |
81 |
3 |
ahitrov@rambler.ru |
} |
82 |
|
|
} |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
# ������� �� ���������� ���������... |
86 |
|
|
if ( $source_class ) { |
87 |
|
|
$m->redirect ("document_links.html?id=$id&class=$class&source_class=$source_class"); |
88 |
|
|
} elsif ( $dest_class ) { |
89 |
|
|
$m->redirect ("document_links.html?id=$id&class=$class&dest_class=$dest_class"); |
90 |
|
|
} else { |
91 |
|
|
$m->redirect ("document_links.html?id=$id&class=$class"); |
92 |
|
|
} |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
</%init> |