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