• sections.html

    521 522  
    312 312 $updated{$oid}{$attr} = $value;
    313 313 }
    314 314 }
    315 warn Dumper \%updated;
    315 warn Dumper \%updated if $DEBUG;
    316 316 my %classes = map { $_->{class} => 1 } values %updated;
    317 317 my $parent_new = $keeper->get_section_by_id( $ARGS{tree} );
    318 318 my $document_access = $user->section_accesses($user, $parent_new->id);
     
    355 355 }
    356 356 }
    357 357 $m->redirect("sections.html?id=".$id.($return_params ? '&'.$return_params : ''));
    358 } 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 : ''));
    358 396 }
    359 397
    360 398 my %filter=();