<%ARGS> $object => undef $SETS => undef <%INIT> use Contenido::File; use vars qw($keeper $request ); $request->{local_codepage} = 'KOI8'; $request->{local_codepage} = 'WIN' if Convert::Cyrillic::cstocs('WIN', 'KOI8', $SETS->{control_charset}) eq 'Контроль'; $request->{local_codepage} = 'UTF8' if Convert::Cyrillic::cstocs('UTF8', 'KOI8', $SETS->{control_charset}) eq 'Контроль'; warn "Contenido Debug: Форма для редактирования пришла в кодировке ".$request->{local_codepage}."\n" if ($state->debug()); my @properties = $object->structure(); for (0..$#properties) { my $prop = $properties[$_]; my $name = $prop->{attr}; my $type = $prop->{type}; next if ($name eq 'sections'); next if ($name eq 'id'); if ($m->comp_exists("/contenido/components/outputs/$type.msn")) { $object->{$name} = $m->comp("/contenido/components/outputs/$type.msn", SETS => $SETS, name => $name, object => $object ); } elsif ( $prop->{type} eq 'image' ) { # -------------------------------------------------------------------------------------- # Добавление одной, отдельно стоящей картинки... if ($SETS->{'_delete_image.'.$name} == 1) { my $IMAGE = eval ('my '.$object->{ $name }); Contenido::File::remove($IMAGE->{'filename'}); Contenido::File::remove($IMAGE->{'mini'}{'filename'}); foreach my $key (keys %{$IMAGE->{'mini'}}) { if (ref $IMAGE->{'mini'}{$key} && ref $IMAGE->{'mini'}{$key} eq 'HASH' && $IMAGE->{'mini'}{$key}->{'filename'}) { Contenido::File::remove($IMAGE->{'mini'}{$key}->{'filename'}) if $IMAGE->{'mini'}{$key}->{'filename'} ne $IMAGE->{'mini'}{'filename'}; } } $object->{$name} = ''; } else { my $IMAGE = undef; if (length($object->{ $name }) > 8) { $IMAGE = eval ('my '.$object->{ $name }); if (ref($IMAGE) ne 'HASH') { $IMAGE = {} }; } $IMAGE = $m->comp('/contenido/components/set_image.msn', default=>$IMAGE, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); if (exists($IMAGE->{filename})) { local $Data::Dumper::Indent = 0; $object->{$name} = Data::Dumper::Dumper($IMAGE); } } } elsif ($prop->{type} =~ /^images/) { # -------------------------------------------------------------------------------------- # А вот это уже сложнее - составление блока из всех картинок... my $IMAGES = {}; if (length($object->{ $name }) > 10) { $IMAGES = eval ('my '.$object->{ $prop->{attr} }); if (ref($IMAGES) ne 'HASH') { $IMAGES = {}; $IMAGES->{maxnumber} = 0; }; } my $maxnumber_ = 0; # Теперь надо просмотреть все аргументы - а вдруг это то, что нам нужно... foreach my $arg (keys(%{ $SETS })) { # Разбиваем все на части, отделяем... my ($partname,undef) = split(/\./,$arg); $partname =~ /^(.+)_(\d+)$/; my ($localname,$number) = ($1, $2); if ( ($localname eq $prop->{attr}) && ($number > 0) && ( $arg eq $localname.'_'.$number )) { # Ура! Нашли элемент! my $partname = $localname.'_'.$number; if ($SETS->{'_delete_image.'.$partname} == 1) { Contenido::File::remove($IMAGES->{'image_'.$number}{"filename"}); Contenido::File::remove($IMAGES->{'image_'.$number}{"mini"}{"filename"}); foreach my $key (keys %{$IMAGES->{'image_'.$number}{'mini'}}) { if (ref $IMAGES->{'image_'.$number}{'mini'}{$key} && ref $IMAGES->{'image_'.$number}{'mini'}{$key} eq 'HASH' && $IMAGES->{'image_'.$number}{'mini'}{$key}->{'filename'}) { Contenido::File::remove($IMAGES->{'image_'.$number}{'mini'}{$key}->{'filename'}) if $IMAGES->{'image_'.$number}{'mini'}{$key}->{'filename'} ne $IMAGES->{'image_'.$number}{'mini'}{'filename'}; } } delete $IMAGES->{'image_'.$number}; } else { my $IMAGE = undef; if (exists($IMAGES->{'image_'.$number})) { $IMAGE = $IMAGES->{'image_'.$number}; }; $IMAGE = $m->comp('/contenido/components/set_image.msn', default=>$IMAGE, field=>$partname, SETS=>$SETS, object=>$object, prop => $prop); if (exists($IMAGE->{filename})) { local $Data::Dumper::Indent = 0; $IMAGE->{number} = $number; $IMAGES->{'image_'.$number} = $IMAGE; $IMAGES->{maxnumber} = $number if ($number > $IMAGES->{maxnumber}); } } } } if ( scalar(keys(%{ $IMAGES })) > 0) { local $Data::Dumper::Indent = 0; $object->{$name} = Data::Dumper::Dumper($IMAGES); } } elsif ( $prop->{type} eq 'multimedia' ) { # -------------------------------------------------------------------------------------- # Добавление одного объект Мультимедиа if ($SETS->{'_delete_multi.'.$name} == 1) { my $BINARY = eval ('my '.$object->{ $name }); Contenido::File::remove($BINARY->{"filename"}); $object->{$name} = ''; } else { my $MULTI = undef; if (length($object->{ $name }) > 8) { $MULTI = eval ('my '.$object->{ $name }); if (ref($MULTI) ne 'HASH') { $MULTI = {} }; } $MULTI = $m->comp('/contenido/components/set_multi.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object); if (exists($MULTI->{filename})) { local $Data::Dumper::Indent = 0; $object->{$name} = Data::Dumper::Dumper($MULTI); } } } elsif ( $prop->{type} eq 'multimedia_new' ) { # -------------------------------------------------------------------------------------- # Добавление одного объект Мультимедиа if ($SETS->{'_delete_multi.'.$name} == 1) { my $BINARY = eval ('my '.$object->{ $name }); Contenido::File::remove($BINARY->{"filename"}); $object->{$name} = ''; } else { my $MULTI = undef; if (length($object->{ $name }) > 8) { $MULTI = eval ('my '.$object->{ $name }); if (ref($MULTI) ne 'HASH') { $MULTI = {} }; } $MULTI = $m->comp('/contenido/components/set_multimedia_new.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); if (exists($MULTI->{filename})) { local $Data::Dumper::Indent = 0; $object->{$name} = Data::Dumper::Dumper($MULTI); } } } elsif ( $prop->{type} eq 'audio' ) { # -------------------------------------------------------------------------------------- # Добавление одного объект Мультимедиа if ($SETS->{'_delete_multi.'.$name} == 1) { my $VAR1 = undef; eval "\$object->{$name}"; my $BINARY = $VAR1; if (ref $BINARY) {$BINARY->remove} $object->{$name} = ''; } else { my $MULTI = undef; if (length($object->$name) > 8) { my $VAR1 = undef; eval "\$object->{$name}"; $MULTI = $VAR1; unless (ref $MULTI) {$MULTI = undef}; } $MULTI = $m->comp('/contenido/components/set_audio.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); if (exists($MULTI->{filename})) { local $Data::Dumper::Indent = 0; $object->{$name} = Data::Dumper::Dumper($MULTI); } } } else { $object->{$name} = $m->comp('/contenido/components/filter.msn', str => $SETS->{$name} ); } } # По идее - мы работаем с ссылкой, так что ничего не надо возвращать! # O-ле! О-ле! О-ле! return 1;