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 |
|
|
my $BINARY = eval ('my '.$object->{ $name }); |
105 |
|
|
Contenido::File::remove($BINARY->{"filename"}); |
106 |
|
|
$object->{$name} = ''; |
107 |
|
|
} 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 |
|
|
my $BINARY = eval ('my '.$object->{ $name }); |
128 |
|
|
Contenido::File::remove($BINARY->{"filename"}); |
129 |
|
|
$object->{$name} = ''; |
130 |
|
|
} 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 |
53 |
ahitrov@rambler.ru |
} elsif ( $prop->{type} eq 'audio' ) { |
145 |
8 |
ahitrov@rambler.ru |
# -------------------------------------------------------------------------------------- |
146 |
|
|
# Добавление одного объект Мультимедиа |
147 |
|
|
|
148 |
|
|
if ($SETS->{'_delete_multi.'.$name} == 1) |
149 |
|
|
{ |
150 |
|
|
my $VAR1 = undef; |
151 |
|
|
eval "\$object->{$name}"; |
152 |
|
|
my $BINARY = $VAR1; |
153 |
|
|
if (ref $BINARY) {$BINARY->remove} |
154 |
|
|
$object->{$name} = ''; |
155 |
|
|
} else { |
156 |
|
|
my $MULTI = undef; |
157 |
|
|
if (length($object->$name) > 8) |
158 |
|
|
{ |
159 |
|
|
my $VAR1 = undef; |
160 |
|
|
eval "\$object->{$name}"; |
161 |
|
|
$MULTI = $VAR1; |
162 |
|
|
unless (ref $MULTI) {$MULTI = undef}; |
163 |
|
|
} |
164 |
|
|
$MULTI = $m->comp('/contenido/components/set_audio.msn', default=>$MULTI, field=>$name, SETS=>$SETS, object=>$object, prop => $prop); |
165 |
|
|
if (exists($MULTI->{filename})) |
166 |
|
|
{ |
167 |
225 |
ahitrov |
$object->$name( $object->_serialize($MULTI) ); |
168 |
8 |
ahitrov@rambler.ru |
} |
169 |
|
|
} |
170 |
|
|
|
171 |
53 |
ahitrov@rambler.ru |
} else { |
172 |
|
|
$object->{$name} = $m->comp('/contenido/components/filter.msn', str => $SETS->{$name} ); |
173 |
8 |
ahitrov@rambler.ru |
} |
174 |
|
|
|
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
# По идее - мы работаем с ссылкой, так что ничего не надо возвращать! |
178 |
|
|
# O-ле! О-ле! О-ле! |
179 |
|
|
return 1; |
180 |
|
|
|
181 |
|
|
</%INIT> |