1 |
8 |
ahitrov@rambler.ru |
<%ARGS> |
2 |
|
|
|
3 |
53 |
ahitrov@rambler.ru |
$object => undef |
4 |
|
|
$SETS => undef |
5 |
8 |
ahitrov@rambler.ru |
|
6 |
|
|
</%ARGS> |
7 |
|
|
<%INIT> |
8 |
53 |
ahitrov@rambler.ru |
|
9 |
|
|
use Contenido::File; |
10 |
8 |
ahitrov@rambler.ru |
use vars qw($keeper $request ); |
11 |
|
|
|
12 |
|
|
$request->{local_codepage} = 'UTF8'; |
13 |
53 |
ahitrov@rambler.ru |
$request->{local_codepage} = 'WIN' if Convert::Cyrillic::cstocs('WIN', 'UTF8', $SETS->{control_charset}) eq 'Контроль'; |
14 |
|
|
$request->{local_codepage} = 'KOI8' if Convert::Cyrillic::cstocs('KOI8', 'UTF8', $SETS->{control_charset}) eq 'Контроль'; |
15 |
8 |
ahitrov@rambler.ru |
|
16 |
|
|
warn "Contenido Debug: Форма для редактирования пришла в кодировке ".$request->{local_codepage}."\n" if ($state->debug()); |
17 |
|
|
|
18 |
|
|
my @properties = $object->structure(); |
19 |
|
|
for (0..$#properties) |
20 |
|
|
{ |
21 |
53 |
ahitrov@rambler.ru |
my $prop = $properties[$_]; |
22 |
|
|
my $name = $prop->{attr}; |
23 |
|
|
my $type = $prop->{type}; |
24 |
8 |
ahitrov@rambler.ru |
|
25 |
53 |
ahitrov@rambler.ru |
next if ($name eq 'sections'); |
26 |
|
|
next if ($name eq 'id'); |
27 |
8 |
ahitrov@rambler.ru |
|
28 |
53 |
ahitrov@rambler.ru |
if ($m->comp_exists("/contenido/components/outputs/$type.msn")) { |
29 |
|
|
$object->{$name} = $m->comp("/contenido/components/outputs/$type.msn", SETS => $SETS, name => $name, object => $object ); |
30 |
|
|
|
31 |
|
|
} elsif ( $prop->{type} eq 'image' ) { |
32 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
33 |
|
|
# Добавление одной, отдельно стоящей картинки... |
34 |
|
|
|
35 |
|
|
if ($SETS->{'_delete_image.'.$name} == 1) |
36 |
|
|
{ |
37 |
113 |
ahitrov |
my $IMAGE = $object->get_image( $name ); |
38 |
|
|
$object->_delete_image( $IMAGE ); |
39 |
|
|
$object->$name(''); |
40 |
8 |
ahitrov@rambler.ru |
} else { |
41 |
113 |
ahitrov |
my $IMAGE = $object->get_image( $name ); |
42 |
|
|
$IMAGE = ref $IMAGE ? $IMAGE : {}; |
43 |
|
|
$IMAGE = $m->comp('/contenido/components/set_image.msn', default=>$IMAGE, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); |
44 |
|
|
if ( exists $IMAGE->{filename} ) { |
45 |
|
|
local $Data::Dumper::Indent = 0; |
46 |
|
|
$object->$name( Data::Dumper::Dumper($IMAGE) ); |
47 |
8 |
ahitrov@rambler.ru |
} |
48 |
|
|
} |
49 |
53 |
ahitrov@rambler.ru |
|
50 |
|
|
} elsif ($prop->{type} =~ /^images/) { |
51 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
52 |
|
|
# А вот это уже сложнее - составление блока из всех картинок... |
53 |
|
|
|
54 |
113 |
ahitrov |
my $IMAGES = $object->get_image( $name ); |
55 |
|
|
if (ref($IMAGES) ne 'HASH') { |
56 |
|
|
$IMAGES = {}; |
57 |
|
|
$IMAGES->{maxnumber} = 0; |
58 |
|
|
}; |
59 |
8 |
ahitrov@rambler.ru |
|
60 |
|
|
# Теперь надо просмотреть все аргументы - а вдруг это то, что нам нужно... |
61 |
|
|
foreach my $arg (keys(%{ $SETS })) |
62 |
|
|
{ |
63 |
113 |
ahitrov |
# Разбиваем все на части, отделяем... |
64 |
|
|
my ($partname,undef) = split(/\./,$arg); |
65 |
|
|
$partname =~ /^(.+)_(\d+)$/; |
66 |
|
|
my ($localname,$number) = ($1, $2); |
67 |
|
|
if ( ($localname eq $prop->{attr}) && ($number > 0) && ( $arg eq $localname.'_'.$number )) { |
68 |
8 |
ahitrov@rambler.ru |
# Ура! Нашли элемент! |
69 |
|
|
|
70 |
|
|
my $partname = $localname.'_'.$number; |
71 |
|
|
|
72 |
113 |
ahitrov |
if ($SETS->{'_delete_image.'.$partname} == 1) { |
73 |
|
|
$object->_delete_image( $IMAGES->{'image_'.$number} ); |
74 |
|
|
delete $IMAGES->{'image_'.$number}; |
75 |
|
|
} else { |
76 |
|
|
my $IMAGE = undef; |
77 |
|
|
if (exists($IMAGES->{'image_'.$number})) { |
78 |
|
|
$IMAGE = $IMAGES->{'image_'.$number}; |
79 |
|
|
}; |
80 |
8 |
ahitrov@rambler.ru |
$IMAGE = $m->comp('/contenido/components/set_image.msn', default=>$IMAGE, field=>$partname, SETS=>$SETS, object=>$object, prop => $prop); |
81 |
113 |
ahitrov |
if (exists($IMAGE->{filename})) { |
82 |
|
|
local $Data::Dumper::Indent = 0; |
83 |
|
|
$IMAGE->{number} = $number; |
84 |
|
|
$IMAGES->{'image_'.$number} = $IMAGE; |
85 |
|
|
$IMAGES->{maxnumber} = $number if ($number > $IMAGES->{maxnumber}); |
86 |
|
|
} |
87 |
|
|
} |
88 |
|
|
} |
89 |
|
|
} |
90 |
8 |
ahitrov@rambler.ru |
|
91 |
113 |
ahitrov |
if ( scalar(keys(%{ $IMAGES })) > 0) { |
92 |
63 |
ahitrov@rambler.ru |
my $maxnumber = 0; |
93 |
|
|
for ( 1..100 ) { |
94 |
|
|
$maxnumber = $_ if exists $IMAGES->{"image_$_"} && $_ > $maxnumber; |
95 |
|
|
} |
96 |
|
|
$IMAGES->{maxnumber} = $maxnumber; |
97 |
113 |
ahitrov |
local $Data::Dumper::Indent = 0; |
98 |
|
|
$object->$name( Data::Dumper::Dumper($IMAGES) ); |
99 |
|
|
} |
100 |
8 |
ahitrov@rambler.ru |
|
101 |
53 |
ahitrov@rambler.ru |
} elsif ( $prop->{type} eq 'multimedia' ) { |
102 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
103 |
|
|
# Добавление одного объект Мультимедиа |
104 |
|
|
|
105 |
|
|
if ($SETS->{'_delete_multi.'.$name} == 1) |
106 |
|
|
{ |
107 |
|
|
my $BINARY = eval ('my '.$object->{ $name }); |
108 |
|
|
Contenido::File::remove($BINARY->{"filename"}); |
109 |
|
|
$object->{$name} = ''; |
110 |
|
|
} else { |
111 |
|
|
my $MULTI = undef; |
112 |
|
|
if (length($object->{ $name }) > 8) |
113 |
|
|
{ |
114 |
|
|
$MULTI = eval ('my '.$object->{ $name }); |
115 |
|
|
if (ref($MULTI) ne 'HASH') { $MULTI = {} }; |
116 |
|
|
} |
117 |
|
|
$MULTI = $m->comp('/contenido/components/set_multi.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object); |
118 |
|
|
if (exists($MULTI->{filename})) |
119 |
|
|
{ |
120 |
|
|
local $Data::Dumper::Indent = 0; |
121 |
|
|
$object->{$name} = Data::Dumper::Dumper($MULTI); |
122 |
|
|
} |
123 |
|
|
} |
124 |
|
|
|
125 |
53 |
ahitrov@rambler.ru |
} elsif ( $prop->{type} eq 'multimedia_new' ) { |
126 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
127 |
|
|
# Добавление одного объект Мультимедиа |
128 |
|
|
|
129 |
|
|
if ($SETS->{'_delete_multi.'.$name} == 1) |
130 |
|
|
{ |
131 |
|
|
my $BINARY = eval ('my '.$object->{ $name }); |
132 |
|
|
Contenido::File::remove($BINARY->{"filename"}); |
133 |
|
|
$object->{$name} = ''; |
134 |
|
|
} else { |
135 |
|
|
my $MULTI = undef; |
136 |
|
|
if (length($object->{ $name }) > 8) |
137 |
|
|
{ |
138 |
|
|
$MULTI = eval ('my '.$object->{ $name }); |
139 |
|
|
if (ref($MULTI) ne 'HASH') { $MULTI = {} }; |
140 |
|
|
} |
141 |
|
|
$MULTI = $m->comp('/contenido/components/set_multimedia_new.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); |
142 |
|
|
if (exists($MULTI->{filename})) |
143 |
|
|
{ |
144 |
|
|
local $Data::Dumper::Indent = 0; |
145 |
|
|
$object->{$name} = Data::Dumper::Dumper($MULTI); |
146 |
|
|
} |
147 |
|
|
} |
148 |
|
|
|
149 |
53 |
ahitrov@rambler.ru |
} elsif ( $prop->{type} eq 'audio' ) { |
150 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
151 |
|
|
# Добавление одного объект Мультимедиа |
152 |
|
|
|
153 |
|
|
if ($SETS->{'_delete_multi.'.$name} == 1) |
154 |
|
|
{ |
155 |
|
|
my $VAR1 = undef; |
156 |
|
|
eval "\$object->{$name}"; |
157 |
|
|
my $BINARY = $VAR1; |
158 |
|
|
if (ref $BINARY) {$BINARY->remove} |
159 |
|
|
$object->{$name} = ''; |
160 |
|
|
} else { |
161 |
|
|
my $MULTI = undef; |
162 |
|
|
if (length($object->$name) > 8) |
163 |
|
|
{ |
164 |
|
|
my $VAR1 = undef; |
165 |
|
|
eval "\$object->{$name}"; |
166 |
|
|
$MULTI = $VAR1; |
167 |
|
|
unless (ref $MULTI) {$MULTI = undef}; |
168 |
|
|
} |
169 |
|
|
$MULTI = $m->comp('/contenido/components/set_audio.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); |
170 |
|
|
if (exists($MULTI->{filename})) |
171 |
|
|
{ |
172 |
|
|
local $Data::Dumper::Indent = 0; |
173 |
|
|
$object->{$name} = Data::Dumper::Dumper($MULTI); |
174 |
|
|
} |
175 |
|
|
} |
176 |
|
|
|
177 |
53 |
ahitrov@rambler.ru |
} else { |
178 |
|
|
$object->{$name} = $m->comp('/contenido/components/filter.msn', str => $SETS->{$name} ); |
179 |
8 |
ahitrov@rambler.ru |
} |
180 |
|
|
|
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
# По идее - мы работаем с ссылкой, так что ничего не надо возвращать! |
184 |
|
|
# O-ле! О-ле! О-ле! |
185 |
|
|
return 1; |
186 |
|
|
|
187 |
|
|
</%INIT> |