Revision 347 (by ahitrov, 2013/05/17 20:16:39) New datatype - multimedia_multi - for multi-file storages (a-la images)
<%args>

	$SETS	=> undef
	$field	=> undef
	$default=> undef
	$object	=> undef
	$prop	=> undef

</%args>
<%init>

return undef unless defined $SETS and defined $field;
#use vars qw($keeper);

# --------------------------------------------------------------------------------------
# Добавление одной картинки

my $BINARY = $default;

if ($SETS->{$field} || $SETS->{"$field.ext_url"}) {

    my $upload;
    if ( $SETS->{$field} ) {
	$upload = $r->upload($field);
    } elsif ( $SETS->{"$field.ext_url"} && $SETS->{"$field.ext_url"} =~ /^(http|https|ftp):\/\/.*/ ) {
	$upload = $SETS->{"$field.ext_url"};
    }
    if ($upload) {

	my $BIN = $object->_store_binary( $upload, attr => $prop->{attr}, prop => $prop );

	if ( ref $BIN eq 'HASH' && exists $BIN->{filename} ) {
		$object->_delete_binary( $default );
		%$BINARY = %$BIN;
	}

    } else {
	warn 'ERROR in incoming POST form: "'.$field.' is not file upload (value: "'.$SETS->{$field}.'")';
    }

}

# Дополнительные поля - берем все, что найдем...

my $pattern = "^".$field.q|\.(.*)$|;

foreach my $localfield (keys(%{ $SETS })) {
    if ($localfield =~ /$pattern/) {
	my $imagefield = $1;
	$BINARY->{$imagefield} = $m->comp("/contenido/components/filter.msn", str => $SETS->{$localfield});
    }
}

return $BINARY;

</%init>