1 |
8 |
ahitrov@rambler.ru |
%# vim:syn=mason |
2 |
|
|
<& "/contenido/components/header.msn" &> |
3 |
|
|
<& "/contenido/components/naviline.msn", sect_id => $owner->id &> |
4 |
|
|
|
5 |
|
|
% if ($error) { |
6 |
|
|
<div align="center" style="font-size:110%; color:red;"> |
7 |
|
|
<% $error %> |
8 |
|
|
</div> |
9 |
|
|
<br><br> |
10 |
|
|
% } |
11 |
|
|
|
12 |
|
|
% if (!ref($document)) { |
13 |
|
|
% if ($id) { |
14 |
|
|
<div align="center" style="font-size:110%; color:red;"> |
15 |
|
|
Документ с идентификатором <% $id %> не найден |
16 |
|
|
</div> |
17 |
|
|
<br><br> |
18 |
|
|
% } elsif ($class) { |
19 |
|
|
<!-- Блок с выбором нового документа для создания --> |
20 |
|
|
<table width="50%" border="0"><tr><td> |
21 |
|
|
<fieldset> |
22 |
|
|
<legend>Выберите тип документа для создания</legend> |
23 |
|
|
<& "/contenido/components/new_objects_form.msn", proto => 'documents', sect_id => $owner->id &> |
24 |
|
|
</fieldset> |
25 |
|
|
</td></tr></table> |
26 |
|
|
% } else { |
27 |
|
|
<div align="center" style="font-size:110%; color:red;"> |
28 |
386 |
ahitrov |
Неверный вызов документа!!! (отсутствуют id и class одновременно) |
29 |
8 |
ahitrov@rambler.ru |
</div> |
30 |
|
|
<br><br> |
31 |
|
|
% } |
32 |
|
|
|
33 |
|
|
% } else { |
34 |
|
|
|
35 |
|
|
<& "/contenido/components/obj_list_js.msn", object => $document &> |
36 |
|
|
<& "/contenido/components/object_form.msn", |
37 |
|
|
object => $document, |
38 |
|
|
proto => 'documents', |
39 |
|
|
sect_id => $owner->id, |
40 |
|
|
clone => $clone, |
41 |
|
|
filter_params => \%filter_params, |
42 |
|
|
&> |
43 |
|
|
% if (ref($document) && ($document->id)) |
44 |
|
|
% { |
45 |
|
|
|
46 |
|
|
<!-- Связи и привязки к рубрикам --> |
47 |
|
|
|
48 |
|
|
<br> |
49 |
|
|
|
50 |
|
|
<table width="100%" cellspacing="5" cellpadding="0" border="0"> |
51 |
|
|
<tr> |
52 |
|
|
<td width=50% valign=top>\ |
53 |
|
|
<& "/contenido/components/document_sections.msn", document => $document &>\ |
54 |
|
|
<& "/contenido/components/user_sections.msn", luser => $document &>\ |
55 |
|
|
% if ( $m->comp_exists ("/contenido/components/pbase_rubrics.msn") ) { |
56 |
|
|
<& "/contenido/components/pbase_rubrics.msn", document => $document &>\ |
57 |
|
|
% } |
58 |
|
|
</td> |
59 |
|
|
<td width=50% valign=top>\ |
60 |
|
|
% if ( $m->comp_exists ("/contenido/components/pbase_links.msn") ) { |
61 |
|
|
<& "/contenido/components/pbase_links.msn", document => $document &>\ |
62 |
|
|
% } |
63 |
|
|
<iframe id="links" src="document_links.html?id=<% $document->id() %>&class=<% $document->class() %>" width="100%" height="700" frameborder="0"></iframe> |
64 |
|
|
|
65 |
|
|
</td> |
66 |
|
|
</tr> |
67 |
|
|
</table> |
68 |
|
|
|
69 |
|
|
<!-- / Связи и привязки к рубрикам --> |
70 |
|
|
|
71 |
|
|
% } |
72 |
|
|
% } |
73 |
|
|
|
74 |
|
|
</body> |
75 |
|
|
</html> |
76 |
|
|
<%ARGS> |
77 |
386 |
ahitrov |
|
78 |
8 |
ahitrov@rambler.ru |
$p => 1 |
79 |
|
|
$class => undef |
80 |
386 |
ahitrov |
$table => undef |
81 |
8 |
ahitrov@rambler.ru |
$sect_id => undef |
82 |
|
|
$s_alias => undef |
83 |
|
|
$id => undef |
84 |
|
|
$delete => undef |
85 |
|
|
$save => undef |
86 |
|
|
$clone => undef |
87 |
|
|
$activate => undef |
88 |
|
|
$deactivate => undef |
89 |
386 |
ahitrov |
|
90 |
8 |
ahitrov@rambler.ru |
</%ARGS> |
91 |
|
|
<%INIT> |
92 |
17 |
ahitrov@rambler.ru |
|
93 |
386 |
ahitrov |
&abort404 unless $class || $table; |
94 |
8 |
ahitrov@rambler.ru |
my $error=''; |
95 |
|
|
### !!! При добавлении переменных в ARGS их надо внести в список исключений в структуре ниже |
96 |
|
|
|
97 |
|
|
my $filter = $m->comp('/contenido/components/context.msn', name => 'filter'); |
98 |
|
|
|
99 |
|
|
my $document; |
100 |
|
|
my $new; |
101 |
|
|
|
102 |
|
|
if ($id && ($id !~ /\D/) && ($id > 0)) { |
103 |
386 |
ahitrov |
$document = $keeper->get_document_by_id($id, $class ? (class => $class) : (table => $table)); |
104 |
|
|
$class ||= $document->class if ref $document; |
105 |
8 |
ahitrov@rambler.ru |
if ( $clone && exists $document->{'attributes'}->{'dtime'} ) { |
106 |
|
|
$document->dtime(undef); |
107 |
|
|
} |
108 |
|
|
} elsif ( ($class) && (length($class)>0) && (! ref($document)) ) { |
109 |
|
|
$document = new $class ($keeper); |
110 |
|
|
$new = 1; |
111 |
232 |
ahitrov |
unless ( $save ) { |
112 |
|
|
my @properties = $document->structure(); |
113 |
|
|
foreach my $prop ( @properties ) { |
114 |
|
|
my $attr = $prop->{attr}; |
115 |
|
|
### !!! Если не стандартная переменная, то можем инициализировать |
116 |
386 |
ahitrov |
if ( exists $ARGS{$attr} && ! grep { $prop->{attr} eq $_ } qw( class table sect_id id delete save clone s_alias activate deactivate p s use_section alpha alpha_search search_by search ) ) { |
117 |
232 |
ahitrov |
$document->$attr($ARGS{$attr}); |
118 |
|
|
} |
119 |
8 |
ahitrov@rambler.ru |
} |
120 |
|
|
} |
121 |
|
|
} |
122 |
17 |
ahitrov@rambler.ru |
&abort404 unless ref $document; |
123 |
8 |
ahitrov@rambler.ru |
|
124 |
|
|
my @props = $document->structure(); |
125 |
|
|
my %filter_params; |
126 |
|
|
if ($ARGS{use_section} && !grep { $_->{attr} eq 'use_section' } @props ) { |
127 |
|
|
$filter_params{use_section} = $ARGS{use_section}; |
128 |
|
|
$filter_params{class} = $document->class; |
129 |
|
|
} |
130 |
|
|
$filter_params{alpha} = $ARGS{alpha} if $ARGS{alpha} && !grep { $_->{attr} eq 'alpha' } @props; |
131 |
|
|
$filter_params{alpha_search} = $ARGS{alpha_search} if $ARGS{alpha_search} && !grep { $_->{attr} eq 'alpha_search' } @props; |
132 |
|
|
$filter_params{search_by} = $ARGS{search_by} if $ARGS{search_by} && !grep { $_->{attr} eq 'search_by' } @props; |
133 |
|
|
$filter_params{search} = $ARGS{search} if $ARGS{search} && !grep { $_->{attr} eq 'search' } @props; |
134 |
|
|
$filter_params{s} = $ARGS{s} if $ARGS{s} && !grep { $_->{attr} eq 's' } @props; |
135 |
|
|
$filter_params{p} = $p if $p > 1; |
136 |
|
|
my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params ); |
137 |
|
|
|
138 |
|
|
|
139 |
|
|
if ($s_alias) { |
140 |
|
|
$sect_id = $project->s_alias->{$s_alias}; |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
if ( (! $sect_id) && (ref($document)) && ($document->id) ) { |
144 |
|
|
$sect_id = $document->section(); |
145 |
|
|
} |
146 |
|
|
my $owner = $keeper->get_section_by_id ($sect_id || $Contenido::Section::ROOT || 1); |
147 |
|
|
|
148 |
|
|
if (! ref($owner)) { |
149 |
|
|
$owner = $keeper->get_section_by_id ($Contenido::Section::ROOT || 1); |
150 |
|
|
} |
151 |
|
|
if (! ref($owner)) { |
152 |
|
|
warn "Contenido Die: Не могу найти корневую секцию\n"; |
153 |
|
|
return undef; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
if (ref($document) && $document->id() && $document->section()) { |
157 |
|
|
my $document_access = $user->section_accesses($user, $owner); |
158 |
|
|
if ($document_access != 2) { |
159 |
|
|
$m->clear_buffer; |
160 |
|
|
$m->abort(403); |
161 |
|
|
} |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
# Удаление... |
165 |
|
|
if (defined($id) && ($id > 0) && ($delete == 1)) { |
166 |
|
|
$document->delete( attachments => 1 ); |
167 |
|
|
|
168 |
|
|
$m->redirect("sections.html?id=".($filter_params{s} || $owner->id).($return_params ? '&'.$return_params : '')); |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
# Активация... |
172 |
|
|
if (defined($id) && ($id > 0) && ($activate == 1)) { |
173 |
|
|
$document->status(1); |
174 |
|
|
$document->store; |
175 |
|
|
|
176 |
|
|
$m->redirect("sections.html?id=".($filter_params{s} || $owner->id).($return_params ? '&'.$return_params : '')); |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
# Дективация... |
180 |
|
|
if (defined($id) && ($id > 0) && ($deactivate == 1)) { |
181 |
|
|
$document->status(0); |
182 |
|
|
$document->store; |
183 |
|
|
|
184 |
|
|
$m->redirect("sections.html?id=".($filter_params{s} || $owner->id).($return_params ? '&'.$return_params : '')); |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
# Сохранение существующего документа или создание нового... |
188 |
|
|
# Кстати, пока никак не обрабатываются связи... |
189 |
|
|
elsif ( $save == 1 ) |
190 |
|
|
{ |
191 |
|
|
my $clonesource; |
192 |
|
|
if ( $clone ) { |
193 |
|
|
$clonesource = $keeper->get_document_by_id ($clone, |
194 |
|
|
class => $document->class, |
195 |
|
|
); |
196 |
|
|
} |
197 |
|
|
if ($m->comp('/contenido/components/set_properties.msn', object => $document, SETS => \%ARGS) != 1) |
198 |
|
|
{ |
199 |
|
|
# Ошибка, надо бы обработать... |
200 |
|
|
warn "Contenido Warning: Не могу установить значения полей!\n"; |
201 |
|
|
} |
202 |
|
|
if ( $clone ) { |
203 |
|
|
$m->comp('/contenido/components/clone_attachments.msn', object => $document, source => $clonesource ); |
204 |
|
|
$document->sections( $clonesource->sections ); |
205 |
|
|
} elsif ( $new ) { |
206 |
|
|
$document->sections( $owner->id, $filter > 0 ? ($filter) : ()); |
207 |
|
|
} |
208 |
|
|
|
209 |
|
|
|
210 |
436 |
ahitrov |
if ( $m->comp_exists('/contenido/components/pre_store.msn') ) { |
211 |
|
|
$m->comp('/contenido/components/pre_store.msn', object => $document, SETS => \%ARGS); |
212 |
|
|
} |
213 |
|
|
|
214 |
8 |
ahitrov@rambler.ru |
unless ($document->store()) { |
215 |
|
|
# Ошибка, надо бы обработать... |
216 |
|
|
$error="Ошибка сохранения ($keeper->{last_error})"; |
217 |
|
|
} else { |
218 |
436 |
ahitrov |
if ( $m->comp_exists('/contenido/components/post_store.msn') ) { |
219 |
|
|
$m->comp('/contenido/components/post_store.msn', object => $document, SETS => \%ARGS); |
220 |
|
|
} |
221 |
8 |
ahitrov@rambler.ru |
|
222 |
|
|
if ($ARGS{_save_and_leave}) { |
223 |
|
|
$m->redirect("sections.html?id=".($filter_params{s} || $owner->id).($return_params ? '&'.$return_params : '')); |
224 |
|
|
} elsif ($ARGS{_save_and_again}) { |
225 |
|
|
$m->redirect("document.html?class=".$document->class()."§_id=".($filter_params{s} || $owner->id).($return_params ? '&'.$return_params : '')); |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
|
229 |
|
|
$m->redirect("document.html?id=".$document->id()."&class=".$document->class().(exists $filter_params{s} ? '&s='.$filter_params{s} : '').($return_params ? '&'.$return_params : '')); |
230 |
|
|
} |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
</%INIT> |