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 |
574 |
ahitrov |
$object->$name( $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 |
574 |
ahitrov |
$object->$name( $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 |
574 |
ahitrov |
$object->$name ( $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 |
562 |
ahitrov |
my $MULTI = $object->get_image( $name ); |
132 |
|
|
$MULTI = ref $MULTI ? $MULTI : {}; |
133 |
8 |
ahitrov@rambler.ru |
$MULTI = $m->comp('/contenido/components/set_multimedia_new.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); |
134 |
|
|
if (exists($MULTI->{filename})) |
135 |
|
|
{ |
136 |
574 |
ahitrov |
$object->$name( $MULTI ); |
137 |
8 |
ahitrov@rambler.ru |
} |
138 |
|
|
} |
139 |
|
|
|
140 |
347 |
ahitrov |
} elsif ($prop->{type} eq 'multimedia_multi') { |
141 |
|
|
# -------------------------------------------------------------------------------------- |
142 |
|
|
# А вот это уже сложнее - составление блока из всех файлов... |
143 |
|
|
|
144 |
|
|
my $FILES = $object->get_image( $name ); |
145 |
|
|
if ( ref($FILES) ne 'HASH' ) { |
146 |
|
|
$FILES = {}; |
147 |
|
|
$FILES->{maxnumber} = 0; |
148 |
|
|
}; |
149 |
|
|
|
150 |
|
|
# Теперь надо просмотреть все аргументы - а вдруг это то, что нам нужно... |
151 |
|
|
foreach my $arg (keys(%{ $SETS })) |
152 |
|
|
{ |
153 |
|
|
# Разбиваем все на части, отделяем... |
154 |
|
|
my ($partname,undef) = split(/\./,$arg); |
155 |
|
|
$partname =~ /^(.+)_(\d+)$/; |
156 |
|
|
my ($localname,$number) = ($1, $2); |
157 |
|
|
if ( ($localname eq $prop->{attr}) && ($number > 0) && ( $arg eq $localname.'_'.$number )) { |
158 |
|
|
# Ура! Нашли элемент! |
159 |
|
|
|
160 |
|
|
my $partname = $localname.'_'.$number; |
161 |
|
|
|
162 |
|
|
if ($SETS->{'_delete_multi.'.$partname} == 1) { |
163 |
|
|
$object->_delete_binary( $FILES->{'file_'.$number} ); |
164 |
|
|
delete $FILES->{'file_'.$number}; |
165 |
|
|
} else { |
166 |
|
|
my $MULTI = undef; |
167 |
|
|
if (exists($FILES->{'file_'.$number})) { |
168 |
|
|
$MULTI = $FILES->{'file_'.$number}; |
169 |
|
|
}; |
170 |
|
|
$MULTI = $m->comp('/contenido/components/set_multimedia_new.msn', default=>$MULTI, field=>$partname, SETS=>$SETS, object=>$object, prop => $prop); |
171 |
|
|
if (exists($MULTI->{filename})) { |
172 |
|
|
$MULTI->{number} = $number; |
173 |
|
|
$FILES->{'file_'.$number} = $MULTI; |
174 |
|
|
$FILES->{maxnumber} = $number if ($number > $FILES->{maxnumber}); |
175 |
|
|
} |
176 |
|
|
} |
177 |
|
|
} |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
if ( scalar(keys(%{ $FILES })) > 0) { |
181 |
|
|
my $maxnumber = 0; |
182 |
|
|
for ( 1..100 ) { |
183 |
|
|
$maxnumber = $_ if exists $FILES->{"file_$_"} && $_ > $maxnumber; |
184 |
|
|
} |
185 |
|
|
$FILES->{maxnumber} = $maxnumber; |
186 |
574 |
ahitrov |
$object->$name( $FILES ); |
187 |
347 |
ahitrov |
} |
188 |
|
|
|
189 |
53 |
ahitrov@rambler.ru |
} elsif ( $prop->{type} eq 'audio' ) { |
190 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
191 |
|
|
# Добавление одного объект Мультимедиа |
192 |
|
|
|
193 |
|
|
if ($SETS->{'_delete_multi.'.$name} == 1) |
194 |
|
|
{ |
195 |
|
|
my $VAR1 = undef; |
196 |
|
|
eval "\$object->{$name}"; |
197 |
|
|
my $BINARY = $VAR1; |
198 |
|
|
if (ref $BINARY) {$BINARY->remove} |
199 |
|
|
$object->{$name} = ''; |
200 |
|
|
} else { |
201 |
|
|
my $MULTI = undef; |
202 |
|
|
if (length($object->$name) > 8) |
203 |
|
|
{ |
204 |
|
|
my $VAR1 = undef; |
205 |
|
|
eval "\$object->{$name}"; |
206 |
|
|
$MULTI = $VAR1; |
207 |
|
|
unless (ref $MULTI) {$MULTI = undef}; |
208 |
|
|
} |
209 |
|
|
$MULTI = $m->comp('/contenido/components/set_audio.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); |
210 |
|
|
if (exists($MULTI->{filename})) |
211 |
|
|
{ |
212 |
574 |
ahitrov |
$object->$name( $MULTI ); |
213 |
8 |
ahitrov@rambler.ru |
} |
214 |
|
|
} |
215 |
|
|
|
216 |
53 |
ahitrov@rambler.ru |
} else { |
217 |
|
|
$object->{$name} = $m->comp('/contenido/components/filter.msn', str => $SETS->{$name} ); |
218 |
8 |
ahitrov@rambler.ru |
} |
219 |
|
|
|
220 |
|
|
} |
221 |
|
|
|
222 |
|
|
# По идее - мы работаем с ссылкой, так что ничего не надо возвращать! |
223 |
|
|
# O-ле! О-ле! О-ле! |
224 |
|
|
return 1; |
225 |
|
|
|
226 |
|
|
</%INIT> |