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