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