Revision 54 (by ahitrov@rambler.ru, 2010/08/26 17:02:58) Избавляемся от одного противного артефакта
<%ARGS>

	$object	=> undef
	$SETS	=> undef

</%ARGS>
<%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;

</%INIT>