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 |
225 |
ahitrov |
$object->$name( $object->_serialize($IMAGE) ); |
46 |
8 |
ahitrov@rambler.ru |
} |
47 |
|
|
} |
48 |
53 |
ahitrov@rambler.ru |
|
49 |
|
|
} elsif ($prop->{type} =~ /^images/) { |
50 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
51 |
|
|
# А вот это уже сложнее - составление блока из всех картинок... |
52 |
|
|
|
53 |
113 |
ahitrov |
my $IMAGES = $object->get_image( $name ); |
54 |
|
|
if (ref($IMAGES) ne 'HASH') { |
55 |
|
|
$IMAGES = {}; |
56 |
|
|
$IMAGES->{maxnumber} = 0; |
57 |
|
|
}; |
58 |
8 |
ahitrov@rambler.ru |
|
59 |
|
|
# Теперь надо просмотреть все аргументы - а вдруг это то, что нам нужно... |
60 |
|
|
foreach my $arg (keys(%{ $SETS })) |
61 |
|
|
{ |
62 |
113 |
ahitrov |
# Разбиваем все на части, отделяем... |
63 |
|
|
my ($partname,undef) = split(/\./,$arg); |
64 |
|
|
$partname =~ /^(.+)_(\d+)$/; |
65 |
|
|
my ($localname,$number) = ($1, $2); |
66 |
|
|
if ( ($localname eq $prop->{attr}) && ($number > 0) && ( $arg eq $localname.'_'.$number )) { |
67 |
8 |
ahitrov@rambler.ru |
# Ура! Нашли элемент! |
68 |
|
|
|
69 |
|
|
my $partname = $localname.'_'.$number; |
70 |
|
|
|
71 |
113 |
ahitrov |
if ($SETS->{'_delete_image.'.$partname} == 1) { |
72 |
|
|
$object->_delete_image( $IMAGES->{'image_'.$number} ); |
73 |
|
|
delete $IMAGES->{'image_'.$number}; |
74 |
|
|
} else { |
75 |
|
|
my $IMAGE = undef; |
76 |
|
|
if (exists($IMAGES->{'image_'.$number})) { |
77 |
|
|
$IMAGE = $IMAGES->{'image_'.$number}; |
78 |
|
|
}; |
79 |
8 |
ahitrov@rambler.ru |
$IMAGE = $m->comp('/contenido/components/set_image.msn', default=>$IMAGE, field=>$partname, SETS=>$SETS, object=>$object, prop => $prop); |
80 |
113 |
ahitrov |
if (exists($IMAGE->{filename})) { |
81 |
|
|
$IMAGE->{number} = $number; |
82 |
|
|
$IMAGES->{'image_'.$number} = $IMAGE; |
83 |
|
|
$IMAGES->{maxnumber} = $number if ($number > $IMAGES->{maxnumber}); |
84 |
|
|
} |
85 |
|
|
} |
86 |
|
|
} |
87 |
|
|
} |
88 |
8 |
ahitrov@rambler.ru |
|
89 |
113 |
ahitrov |
if ( scalar(keys(%{ $IMAGES })) > 0) { |
90 |
63 |
ahitrov@rambler.ru |
my $maxnumber = 0; |
91 |
|
|
for ( 1..100 ) { |
92 |
|
|
$maxnumber = $_ if exists $IMAGES->{"image_$_"} && $_ > $maxnumber; |
93 |
|
|
} |
94 |
|
|
$IMAGES->{maxnumber} = $maxnumber; |
95 |
225 |
ahitrov |
$object->$name( $object->_serialize($IMAGES) ); |
96 |
113 |
ahitrov |
} |
97 |
8 |
ahitrov@rambler.ru |
|
98 |
53 |
ahitrov@rambler.ru |
} elsif ( $prop->{type} eq 'multimedia' ) { |
99 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
100 |
|
|
# Добавление одного объект Мультимедиа |
101 |
|
|
|
102 |
|
|
if ($SETS->{'_delete_multi.'.$name} == 1) |
103 |
|
|
{ |
104 |
347 |
ahitrov |
my $BINARY = $object->get_image( $name ); |
105 |
|
|
$object->_delete_binary( $BINARY ); |
106 |
|
|
$object->$name(''); |
107 |
8 |
ahitrov@rambler.ru |
} else { |
108 |
|
|
my $MULTI = undef; |
109 |
|
|
if (length($object->{ $name }) > 8) |
110 |
|
|
{ |
111 |
|
|
$MULTI = eval ('my '.$object->{ $name }); |
112 |
|
|
if (ref($MULTI) ne 'HASH') { $MULTI = {} }; |
113 |
|
|
} |
114 |
|
|
$MULTI = $m->comp('/contenido/components/set_multi.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object); |
115 |
|
|
if (exists($MULTI->{filename})) |
116 |
|
|
{ |
117 |
225 |
ahitrov |
$object->$name ( $object->_serialize($MULTI) ); |
118 |
8 |
ahitrov@rambler.ru |
} |
119 |
|
|
} |
120 |
|
|
|
121 |
53 |
ahitrov@rambler.ru |
} elsif ( $prop->{type} eq 'multimedia_new' ) { |
122 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
123 |
|
|
# Добавление одного объект Мультимедиа |
124 |
|
|
|
125 |
|
|
if ($SETS->{'_delete_multi.'.$name} == 1) |
126 |
|
|
{ |
127 |
347 |
ahitrov |
my $BINARY = $object->get_image( $name ); |
128 |
|
|
$object->_delete_binary( $BINARY ); |
129 |
|
|
$object->$name(''); |
130 |
8 |
ahitrov@rambler.ru |
} else { |
131 |
|
|
my $MULTI = undef; |
132 |
|
|
if (length($object->{ $name }) > 8) |
133 |
|
|
{ |
134 |
|
|
$MULTI = eval ('my '.$object->{ $name }); |
135 |
|
|
if (ref($MULTI) ne 'HASH') { $MULTI = {} }; |
136 |
|
|
} |
137 |
|
|
$MULTI = $m->comp('/contenido/components/set_multimedia_new.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); |
138 |
|
|
if (exists($MULTI->{filename})) |
139 |
|
|
{ |
140 |
225 |
ahitrov |
$object->$name( $object->_serialize($MULTI) ); |
141 |
8 |
ahitrov@rambler.ru |
} |
142 |
|
|
} |
143 |
|
|
|
144 |
347 |
ahitrov |
} elsif ($prop->{type} eq 'multimedia_multi') { |
145 |
|
|
# -------------------------------------------------------------------------------------- |
146 |
|
|
# А вот это уже сложнее - составление блока из всех файлов... |
147 |
|
|
|
148 |
|
|
my $FILES = $object->get_image( $name ); |
149 |
|
|
if ( ref($FILES) ne 'HASH' ) { |
150 |
|
|
$FILES = {}; |
151 |
|
|
$FILES->{maxnumber} = 0; |
152 |
|
|
}; |
153 |
|
|
|
154 |
|
|
# Теперь надо просмотреть все аргументы - а вдруг это то, что нам нужно... |
155 |
|
|
foreach my $arg (keys(%{ $SETS })) |
156 |
|
|
{ |
157 |
|
|
# Разбиваем все на части, отделяем... |
158 |
|
|
my ($partname,undef) = split(/\./,$arg); |
159 |
|
|
$partname =~ /^(.+)_(\d+)$/; |
160 |
|
|
my ($localname,$number) = ($1, $2); |
161 |
|
|
if ( ($localname eq $prop->{attr}) && ($number > 0) && ( $arg eq $localname.'_'.$number )) { |
162 |
|
|
# Ура! Нашли элемент! |
163 |
|
|
|
164 |
|
|
my $partname = $localname.'_'.$number; |
165 |
|
|
|
166 |
|
|
if ($SETS->{'_delete_multi.'.$partname} == 1) { |
167 |
|
|
$object->_delete_binary( $FILES->{'file_'.$number} ); |
168 |
|
|
delete $FILES->{'file_'.$number}; |
169 |
|
|
} else { |
170 |
|
|
my $MULTI = undef; |
171 |
|
|
if (exists($FILES->{'file_'.$number})) { |
172 |
|
|
$MULTI = $FILES->{'file_'.$number}; |
173 |
|
|
}; |
174 |
|
|
$MULTI = $m->comp('/contenido/components/set_multimedia_new.msn', default=>$MULTI, field=>$partname, SETS=>$SETS, object=>$object, prop => $prop); |
175 |
|
|
if (exists($MULTI->{filename})) { |
176 |
|
|
$MULTI->{number} = $number; |
177 |
|
|
$FILES->{'file_'.$number} = $MULTI; |
178 |
|
|
$FILES->{maxnumber} = $number if ($number > $FILES->{maxnumber}); |
179 |
|
|
} |
180 |
|
|
} |
181 |
|
|
} |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
if ( scalar(keys(%{ $FILES })) > 0) { |
185 |
|
|
my $maxnumber = 0; |
186 |
|
|
for ( 1..100 ) { |
187 |
|
|
$maxnumber = $_ if exists $FILES->{"file_$_"} && $_ > $maxnumber; |
188 |
|
|
} |
189 |
|
|
$FILES->{maxnumber} = $maxnumber; |
190 |
|
|
$object->$name( $object->_serialize($FILES) ); |
191 |
|
|
} |
192 |
|
|
|
193 |
53 |
ahitrov@rambler.ru |
} elsif ( $prop->{type} eq 'audio' ) { |
194 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
195 |
|
|
# Добавление одного объект Мультимедиа |
196 |
|
|
|
197 |
|
|
if ($SETS->{'_delete_multi.'.$name} == 1) |
198 |
|
|
{ |
199 |
|
|
my $VAR1 = undef; |
200 |
|
|
eval "\$object->{$name}"; |
201 |
|
|
my $BINARY = $VAR1; |
202 |
|
|
if (ref $BINARY) {$BINARY->remove} |
203 |
|
|
$object->{$name} = ''; |
204 |
|
|
} else { |
205 |
|
|
my $MULTI = undef; |
206 |
|
|
if (length($object->$name) > 8) |
207 |
|
|
{ |
208 |
|
|
my $VAR1 = undef; |
209 |
|
|
eval "\$object->{$name}"; |
210 |
|
|
$MULTI = $VAR1; |
211 |
|
|
unless (ref $MULTI) {$MULTI = undef}; |
212 |
|
|
} |
213 |
|
|
$MULTI = $m->comp('/contenido/components/set_audio.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); |
214 |
|
|
if (exists($MULTI->{filename})) |
215 |
|
|
{ |
216 |
225 |
ahitrov |
$object->$name( $object->_serialize($MULTI) ); |
217 |
8 |
ahitrov@rambler.ru |
} |
218 |
|
|
} |
219 |
|
|
|
220 |
53 |
ahitrov@rambler.ru |
} else { |
221 |
|
|
$object->{$name} = $m->comp('/contenido/components/filter.msn', str => $SETS->{$name} ); |
222 |
8 |
ahitrov@rambler.ru |
} |
223 |
|
|
|
224 |
|
|
} |
225 |
|
|
|
226 |
|
|
# По идее - мы работаем с ссылкой, так что ничего не надо возвращать! |
227 |
|
|
# O-ле! О-ле! О-ле! |
228 |
|
|
return 1; |
229 |
|
|
|
230 |
|
|
</%INIT> |