Line # Revision Author
1 198 ahitrov %# 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 Неверный вызов документа!!! (отсутствуют id и class одновременно)
29 </div>
30 <br><br>
31 % }
32
33 % } else {
34
35 <& "/contenido/components/obj_list_js.msn", object => $document &>
36 <& "/contenido/webshop/components/order_form.msn",
37 object => $document,
38 proto => 'documents',
39 sect_id => $owner->id,
40 filter_params => \%filter_params,
41 &>
42 % }
43
44 </body>
45 </html>
46 <%ARGS>
47 $p => 1
48 $class => 'webshop::Order'
49 $sect_id => undef
50 $s_alias => undef
51 $id => undef
52 $delete => undef
53 $save => undef
54 </%ARGS>
55 <%INIT>
56
57 &abort404 unless $class;
58 my $error='';
59 ### !!! При добавлении переменных в ARGS их надо внести в список исключений в структуре ниже
60
61 my $filter = $m->comp('/contenido/components/context.msn', name => 'filter');
62
63 my $document;
64 my $new;
65 my $now = Contenido::DateTime->new;
66
67 if ($id && ($id !~ /\D/) && ($id > 0)) {
68 $document = $keeper->get_document_by_id($id, class=>$class);
69 } elsif ( ($class) && (length($class)>0) && (! ref($document)) ) {
70 $document = new $class ($keeper);
71 $new = 1;
72 my @properties = $document->structure();
73 foreach my $prop ( @properties ) {
74 my $attr = $prop->{attr};
75 ### !!! Если не стандартная переменная, то можем инициализировать
76 if ( exists $ARGS{$attr} && ! grep { $prop->{attr} eq $_ } qw( class sect_id id delete save s_alias p s use_section alpha alpha_search search_by search ) ) {
77 $document->$attr($ARGS{$attr});
78 }
79 }
80 }
81 &abort404 unless ref $document;
82
83 my @props = $document->structure();
84 my %filter_params;
85 if ($ARGS{use_section} && !grep { $_->{attr} eq 'use_section' } @props ) {
86 $filter_params{use_section} = $ARGS{use_section};
87 $filter_params{class} = $document->class;
88 }
89 $filter_params{alpha} = $ARGS{alpha} if $ARGS{alpha} && !grep { $_->{attr} eq 'alpha' } @props;
90 $filter_params{alpha_search} = $ARGS{alpha_search} if $ARGS{alpha_search} && !grep { $_->{attr} eq 'alpha_search' } @props;
91 $filter_params{search_by} = $ARGS{search_by} if $ARGS{search_by} && !grep { $_->{attr} eq 'search_by' } @props;
92 $filter_params{search} = $ARGS{search} if $ARGS{search} && !grep { $_->{attr} eq 'search' } @props;
93 $filter_params{s} = $ARGS{s} if $ARGS{s} && !grep { $_->{attr} eq 's' } @props;
94 $filter_params{p} = $p if $p > 1;
95 my $return_params = join ('&', map { $_.'='.$filter_params{$_} } grep { $_ ne 's' } keys %filter_params );
96
97
98 if ($s_alias) {
99 $sect_id = $project->s_alias->{$s_alias};
100 }
101
102 if ( (! $sect_id) && (ref($document)) && ($document->id) ) {
103 $sect_id = $document->section();
104 }
105 my $owner = $keeper->get_section_by_id ($sect_id || $Contenido::Section::ROOT || 1);
106
107 if (! ref($owner)) {
108 $owner = $keeper->get_section_by_id ($Contenido::Section::ROOT || 1);
109 }
110 if (! ref($owner)) {
111 warn "Contenido Die: Не могу найти корневую секцию\n";
112 return undef;
113 }
114
115 if ( ref $document ) {
116 $document->manager_id( $user->id );
117 $document->store;
118 }
119 if (ref($document) && $document->id() && $document->section()) {
120 my $document_access = $user->section_accesses($user, $owner);
121 if ($document_access != 2) {
122 $m->clear_buffer;
123 $m->abort(403);
124 }
125 }
126
127 # Удаление...
128 if (defined($id) && ($id > 0) && $delete) {
129 $document->status( 5 );
130 $document->store;
131
132 $m->redirect("./?ost=1".($return_params ? '&'.$return_params : ''));
133 }
134
135 # Сохранение существующего документа или создание нового...
136 # Кстати, пока никак не обрабатываются связи...
137 elsif ( $save == 1 )
138 {
139 if ($m->comp('/contenido/webshop/components/set_properties.msn', object => $document, SETS => \%ARGS) != 1)
140 {
141 # Ошибка, надо бы обработать...
142 warn "Contenido Warning: Не могу установить значения полей!\n";
143 }
144 if ( $new ) {
145 $document->sections( $owner->id, $filter > 0 ? ($filter) : ());
146 }
147
148 if ( $ARGS{_save_and_deliver} ) {
149 $document->manager_id( $user->id );
150 $document->ftime( $now->ymd('-').' '.$now->hms );
151 $document->status(3);
152 } elsif ( $ARGS{_save_and_complect} ) {
153 $document->manager_id( $user->id );
154 $document->btime( $now->ymd('-').' '.$now->hms );
155 $document->status(2);
156 } elsif ( $ARGS{_save_and_leave} ) {
157 $document->manager_id( undef );
158 $document->status(1);
159 }
160
161 unless ($document->store()) {
162 # Ошибка, надо бы обработать...
163 $error="Ошибка сохранения ($keeper->{last_error})";
164 } else {
165
166 if ($ARGS{_save_and_complect}) {
167 $m->redirect("./?ost=2");
168 } elsif ($ARGS{_save_and_deliver}) {
169 $m->redirect("./?ost=3");
170 } elsif ($ARGS{_save_and_leave}) {
171 $m->redirect("./?ost=1".($return_params ? '&'.$return_params : ''));
172 }
173
174 $m->redirect("take_care.html?id=".$document->id.($return_params ? '&'.$return_params : ''));
175 }
176 }
177
178 </%INIT>