Revision 121 (by ahitrov, 2011/08/22 16:08:07) Admin Interface redesign
New image control
New AI image attachment function - url saving
<%args>

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

</%args>

<%init>
use IO::File;
use Data::Dumper;

return undef unless defined $SETS and defined $field;

# --------------------------------------------------------------------------------------
# ���������� ����� ��������

my $IMAGE = $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 $IMG = $object->_store_image( $upload, attr => $prop->{attr} );

	if ( ref $IMG eq 'HASH' && exists $IMG->{filename} ) {
		$object->_delete_image( $default );
		%$IMAGE = %$IMG;
	}

    } 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;
	$IMAGE->{$imagefield} = $m->comp("/contenido/components/filter.msn", str => $SETS->{$localfield});
    }
}

return $IMAGE;

</%init>